Skip to content

Commit

Permalink
added first test
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed Nov 1, 2024
1 parent 8d17aa4 commit 5ecb775
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const multiMemory = execArgv.includes("--experimental-wasm-multi-memory")
? ["--multi-memory"]
: [];

const AsyncFunction = (async () => {}).constructor;

export async function cliTest(_fixtures) {
suite("CLI", () => {
var tmpDir;
Expand Down Expand Up @@ -119,6 +121,45 @@ export async function cliTest(_fixtures) {
ok(source.toString().includes("export { test"));
});

test("Transpile & Asyncify", 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=asyncify",
"--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(
(fileName) => readFile(`${outDir}/${fileName}`).then((file) => WebAssembly.compile(file)),
{
'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 & Optimize & Minify", async () => {
const name = "flavorful";
const { stderr } = await exec(
Expand Down
Binary file not shown.

0 comments on commit 5ecb775

Please sign in to comment.