Skip to content

Commit c56d988

Browse files
Initialize WASI context in unit test
1 parent ebc86e8 commit c56d988

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ const instantiateComponent = async (rootTestFile) => {
3636
}
3737
const vm = await RubyVM._instantiate(async (jsRuntime) => {
3838
const { cli, clocks, filesystem, io, random, sockets } = preview2Shim;
39+
const dirname = path.dirname(new URL(import.meta.url).pathname);
40+
filesystem._setPreopens({
41+
"/__root__": path.join(dirname, ".."),
42+
"/usr": path.join(process.env.RUBY_BUILD_ROOT, "usr"),
43+
"/bundle": path.join(process.env.RUBY_BUILD_ROOT, "bundle"),
44+
})
45+
cli._setArgs(["ruby.wasm"].concat(process.argv.slice(2)));
46+
cli._setCwd("/")
3947
const root = await instantiate(getCoreModule, {
4048
"ruby:js/js-runtime": jsRuntime,
4149
"wasi:cli/environment": cli.environment,
@@ -59,6 +67,8 @@ const instantiateComponent = async (rootTestFile) => {
5967
"wasi:sockets/tcp": sockets.tcp,
6068
})
6169
return root.rubyRuntime;
70+
}, {
71+
args: ["ruby.wasm", rootTestFile],
6272
})
6373
return { vm };
6474
}

0 commit comments

Comments
 (0)