diff --git a/package.json b/package.json index e20b1f070..fbe7702b7 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "build:types:preview2-shim": "cargo xtask generate wasi-types", "lint": "eslint -c eslintrc.cjs src/**/*.js packages/*/lib/**/*.js", "test:lts": "mocha -u tdd test/test.js --timeout 120000", - "test": "node --stack-trace-limit=100 node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 120000", + "test": "node --experimental-wasm-jspi --stack-trace-limit=100 node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 120000", "prepublishOnly": "cargo xtask build release && npm run test" }, "files": [ diff --git a/test/cli.js b/test/cli.js index 7860e38c5..240d2bc55 100644 --- a/test/cli.js +++ b/test/cli.js @@ -121,7 +121,46 @@ export async function cliTest(_fixtures) { ok(source.toString().includes("export { test")); }); - test("Transpile & Asyncify", async () => { + test("Transpile with Async Mode for JSPI", async () => { + const name = "async_call"; + const { stderr } = await exec( + jcoPath, + "transpile", + `test/fixtures/components/${name}.component.wasm`, + `--name=${name}`, + "--valid-lifting-optimization", + "--tla-compat", + "--instantiation=async", + "--base64-cutoff=0", + "--async-mode=jspi", + "--async-imports=something:test/test-interface#call-async", + "--async-exports=run-async", + "-o", + outDir + ); + strictEqual(stderr, ""); + await writeFile( + `${outDir}/package.json`, + JSON.stringify({ type: "module" }) + ); + const m = await import(`${outDir}/${name}.js`); + const inst = await m.instantiate( + undefined, + { + 'something:test/test-interface': { + callAsync: async () => "called async", + callSync: () => "called sync", + }, + }, + ); + strictEqual(inst.runSync instanceof AsyncFunction, false); + strictEqual(inst.runAsync instanceof AsyncFunction, true); + + strictEqual(inst.runSync(), "called sync"); + strictEqual(await inst.runAsync(), "called async"); + }); + + test("Transpile with Async Mode for Asyncify", async () => { const name = "async_call"; const { stderr } = await exec( jcoPath,