diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/051_wasm_import.ts | 22 | ||||
-rw-r--r-- | cli/tests/051_wasm_import.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/051_wasm_import/remote.ts | 3 | ||||
-rw-r--r-- | cli/tests/051_wasm_import/simple.wasm | bin | 0 -> 226 bytes | |||
-rw-r--r-- | cli/tests/051_wasm_import/simple.wat | 31 | ||||
-rw-r--r-- | cli/tests/051_wasm_import/wasm-dep.js | 17 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 6 |
7 files changed, 80 insertions, 0 deletions
diff --git a/cli/tests/051_wasm_import.ts b/cli/tests/051_wasm_import.ts new file mode 100644 index 000000000..7000657c3 --- /dev/null +++ b/cli/tests/051_wasm_import.ts @@ -0,0 +1,22 @@ +import { add, addImported, addRemote } from "./051_wasm_import/simple.wasm"; +import { state } from "./051_wasm_import/wasm-dep.js"; + +function assertEquals(actual: unknown, expected: unknown, msg?: string): void { + if (actual !== expected) { + throw new Error(msg); + } +} + +assertEquals(state, "WASM Start Executed", "Incorrect state"); + +assertEquals(add(10, 20), 30, "Incorrect add"); + +assertEquals(addImported(0), 42, "Incorrect addImported"); + +assertEquals(state, "WASM JS Function Executed", "Incorrect state"); + +assertEquals(addImported(1), 43, "Incorrect addImported"); + +assertEquals(addRemote(1), 2020, "Incorrect addRemote"); + +console.log("Passed"); diff --git a/cli/tests/051_wasm_import.ts.out b/cli/tests/051_wasm_import.ts.out new file mode 100644 index 000000000..863339fb8 --- /dev/null +++ b/cli/tests/051_wasm_import.ts.out @@ -0,0 +1 @@ +Passed diff --git a/cli/tests/051_wasm_import/remote.ts b/cli/tests/051_wasm_import/remote.ts new file mode 100644 index 000000000..761a5248e --- /dev/null +++ b/cli/tests/051_wasm_import/remote.ts @@ -0,0 +1,3 @@ +export function jsRemoteFn(): number { + return 2019; +} diff --git a/cli/tests/051_wasm_import/simple.wasm b/cli/tests/051_wasm_import/simple.wasm Binary files differnew file mode 100644 index 000000000..8e544fe30 --- /dev/null +++ b/cli/tests/051_wasm_import/simple.wasm diff --git a/cli/tests/051_wasm_import/simple.wat b/cli/tests/051_wasm_import/simple.wat new file mode 100644 index 000000000..5e73db97b --- /dev/null +++ b/cli/tests/051_wasm_import/simple.wat @@ -0,0 +1,31 @@ +;; From https://github.com/nodejs/node/blob/bbc254db5db672643aad89a436a4938412a5704e/test/fixtures/es-modules/simple.wat +;; MIT Licensed +;; $ wat2wasm simple.wat -o simple.wasm + +(module + (import "./wasm-dep.js" "jsFn" (func $jsFn (result i32))) + (import "./wasm-dep.js" "jsInitFn" (func $jsInitFn)) + (import "http://127.0.0.1:4545/cli/tests/051_wasm_import/remote.ts" "jsRemoteFn" (func $jsRemoteFn (result i32))) + (export "add" (func $add)) + (export "addImported" (func $addImported)) + (export "addRemote" (func $addRemote)) + (start $startFn) + (func $startFn + call $jsInitFn + ) + (func $add (param $a i32) (param $b i32) (result i32) + local.get $a + local.get $b + i32.add + ) + (func $addImported (param $a i32) (result i32) + local.get $a + call $jsFn + i32.add + ) + (func $addRemote (param $a i32) (result i32) + local.get $a + call $jsRemoteFn + i32.add + ) +) diff --git a/cli/tests/051_wasm_import/wasm-dep.js b/cli/tests/051_wasm_import/wasm-dep.js new file mode 100644 index 000000000..70b16348b --- /dev/null +++ b/cli/tests/051_wasm_import/wasm-dep.js @@ -0,0 +1,17 @@ +function assertEquals(actual, expected, msg) { + if (actual !== expected) { + throw new Error(msg || ""); + } +} + +export function jsFn() { + state = "WASM JS Function Executed"; + return 42; +} + +export let state = "JS Function Executed"; + +export function jsInitFn() { + assertEquals(state, "JS Function Executed", "Incorrect state"); + state = "WASM Start Executed"; +} diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index b8dab2de8..a366838a1 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -356,6 +356,12 @@ itest!(_050_more_jsons { output: "050_more_jsons.ts.out", }); +itest!(_051_wasm_import { + args: "run --reload --allow-net --allow-read 051_wasm_import.ts", + output: "051_wasm_import.ts.out", + http_server: true, +}); + itest!(lock_check_ok { args: "run --lock=lock_check_ok.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts", output: "003_relative_import.ts.out", |