From 5ecb77572fe46655cb7ab5d42bc96a7d38bba54a Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Fri, 1 Nov 2024 15:23:47 -0500 Subject: [PATCH] added first test --- test/cli.js | 41 ++++++++++++++++++ .../components/async_call.component.wasm | Bin 0 -> 21690 bytes 2 files changed, 41 insertions(+) create mode 100644 test/fixtures/components/async_call.component.wasm diff --git a/test/cli.js b/test/cli.js index 68a459f43..1ba097acd 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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; @@ -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( diff --git a/test/fixtures/components/async_call.component.wasm b/test/fixtures/components/async_call.component.wasm new file mode 100644 index 0000000000000000000000000000000000000000..a52483904a23a4cb7b3ca0507f60ee81b5e8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