Skip to content

Commit

Permalink
added jspi test
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed Nov 3, 2024
1 parent 80a83f8 commit ba1068c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
41 changes: 40 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ba1068c

Please sign in to comment.