Fix test harness for the latest main XCTest

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.
This commit is contained in:
Yuta Saito 2024-04-05 02:13:31 +09:00
parent 8bd1d02f00
commit f286203b0d
4 changed files with 21 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -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);
@ -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,
},
});
@ -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;
};

1
package-lock.json generated
View File

@ -13,6 +13,7 @@
"@wasmer/wasmfs": "^0.12.0",
"esbuild": "^0.14.38",
"npm-run-all": "^4.1.5",
"path-browserify": "^1.0.1",
"reconnecting-websocket": "^4.4.0"
}
},

View File

@ -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"