Skip to content

Commit

Permalink
Fix test harness for the latest main XCTest
Browse files Browse the repository at this point in the history
The latest XCTest bundled in Swift SDK for Wasm requires `Bundle.main` access to
minimize behavior difference from other platforms. `Bundle.main`
requires `argv[0]` and file system access to get the main bundle path.
  • Loading branch information
kateinoigakukun committed Apr 4, 2024
1 parent 8bd1d02 commit f286203
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
18 changes: 9 additions & 9 deletions Sources/CartonKit/Server/StaticArchive.swift

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions entrypoint/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import { WASI } from "@wasmer/wasi";
import { WasmFs } from "@wasmer/wasmfs";
import * as path from "path-browserify";

export const WasmRunner = (rawOptions, SwiftRuntime) => {
const options = defaultRunnerOptions(rawOptions);
Expand All @@ -34,12 +35,18 @@ export const WasmRunner = (rawOptions, SwiftRuntime) => {
}
);

wasmFs.fs.mkdirSync("/sandbox");

const wasi = new WASI({
args: options.args,
env: {},
preopenDirectories: {
"/": "/sandbox",
},
bindings: {
...WASI.defaultBindings,
fs: wasmFs.fs,
path: path,
},
});

Expand Down Expand Up @@ -100,13 +107,13 @@ export const WasmRunner = (rawOptions, SwiftRuntime) => {
const defaultRunnerOptions = (options) => {
if (!options) return defaultRunnerOptions({});
if (!options.onStdout) {
options.onStdout = () => {};
options.onStdout = () => { };
}
if (!options.onStderr) {
options.onStderr = () => {};
options.onStderr = () => { };
}
if (!options.args) {
options.args = [];
options.args = ["main.wasm"];
}
return options;
};
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"devDependencies": {
"@wasmer/wasi": "^0.12.0",
"@wasmer/wasmfs": "^0.12.0",
"path-browserify": "^1.0.1",
"esbuild": "^0.14.38",
"npm-run-all": "^4.1.5",
"reconnecting-websocket": "^4.4.0"
Expand Down

0 comments on commit f286203

Please sign in to comment.