// Runs a wasm32-wasi program (a Zig test binary) under Node's WASI, with // the rest of the arguments as its own; exits with its exit code. // usage: node tools/wasi_run.mjs program.wasm [args...] import {readFile} from 'node:fs/promises'; import {WASI} from 'node:wasi'; const wasi = new WASI({version: 'preview1', args: process.argv.slice(2), env: {}, returnOnExit: true}); const module = await WebAssembly.compile(await readFile(process.argv[2])); process.exitCode = wasi.start(await WebAssembly.instantiate(module, wasi.getImportObject()));