Skip to content

Commit

Permalink
feature detect jspi support in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed Nov 3, 2024
1 parent ba1068c commit 34e0f49
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,44 +121,46 @@ export async function cliTest(_fixtures) {
ok(source.toString().includes("export { test"));
});

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",
if (typeof WebAssembly.Suspending === 'function') {
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 instanceof AsyncFunction, false);
strictEqual(inst.runAsync instanceof AsyncFunction, true);

strictEqual(inst.runSync(), "called sync");
strictEqual(await inst.runAsync(), "called async");
});
strictEqual(inst.runSync(), "called sync");
strictEqual(await inst.runAsync(), "called async");
});
}

test("Transpile with Async Mode for Asyncify", async () => {
const name = "async_call";
Expand Down

0 comments on commit 34e0f49

Please sign in to comment.