diff --git a/crates/cli-support/tests/snapshots/test_add__nodejs_module_js.snap b/crates/cli-support/tests/snapshots/test_add__nodejs_module_js.snap new file mode 100644 index 00000000000..dfe2a90fa2d --- /dev/null +++ b/crates/cli-support/tests/snapshots/test_add__nodejs_module_js.snap @@ -0,0 +1,8 @@ +--- +source: crates/cli-support/tests/test_add.rs +expression: output.js() +--- +let wasm; + export function __wbg_set_wasm(val) { + wasm = val; + } diff --git a/crates/cli-support/tests/snapshots/test_add__nodejs_module_start.snap b/crates/cli-support/tests/snapshots/test_add__nodejs_module_start.snap new file mode 100644 index 00000000000..70020d9a5df --- /dev/null +++ b/crates/cli-support/tests/snapshots/test_add__nodejs_module_start.snap @@ -0,0 +1,20 @@ +--- +source: crates/cli-support/tests/test_add.rs +expression: output.start().unwrap() +--- +let imports = {}; + +import * as path from 'node:path'; +import * as fs from 'node:fs'; +import * as process from 'node:process'; + +let file = path.dirname(new URL(import.meta.url).pathname); +if (process.platform === 'win32') { + file = file.substring(1); +} +const bytes = fs.readFileSync(path.join(file, 'add_bg.wasm')); + +const wasmModule = new WebAssembly.Module(bytes); +const wasmInstance = new WebAssembly.Instance(wasmModule, imports); +const wasm = wasmInstance.exports; +export const __wasm = wasm; diff --git a/crates/cli-support/tests/snapshots/test_native_add__nodejs_module_js.snap b/crates/cli-support/tests/snapshots/test_native_add__nodejs_module_js.snap new file mode 100644 index 00000000000..5d8156695ae --- /dev/null +++ b/crates/cli-support/tests/snapshots/test_native_add__nodejs_module_js.snap @@ -0,0 +1,8 @@ +--- +source: crates/cli-support/tests/test_native_add.rs +expression: output.js() +--- +let wasm; + export function __wbg_set_wasm(val) { + wasm = val; + } diff --git a/crates/cli-support/tests/snapshots/test_native_add__nodejs_module_start.snap b/crates/cli-support/tests/snapshots/test_native_add__nodejs_module_start.snap new file mode 100644 index 00000000000..a22daba3930 --- /dev/null +++ b/crates/cli-support/tests/snapshots/test_native_add__nodejs_module_start.snap @@ -0,0 +1,22 @@ +--- +source: crates/cli-support/tests/test_native_add.rs +expression: output.start().unwrap() +--- +let imports = {}; +import * as import0 from 'env'; +imports['env'] = import0; + +import * as path from 'node:path'; +import * as fs from 'node:fs'; +import * as process from 'node:process'; + +let file = path.dirname(new URL(import.meta.url).pathname); +if (process.platform === 'win32') { + file = file.substring(1); +} +const bytes = fs.readFileSync(path.join(file, 'native_add_bg.wasm')); + +const wasmModule = new WebAssembly.Module(bytes); +const wasmInstance = new WebAssembly.Instance(wasmModule, imports); +const wasm = wasmInstance.exports; +export const __wasm = wasm; diff --git a/crates/cli-support/tests/test_add.rs b/crates/cli-support/tests/test_add.rs index 74fe4ccc1c7..cd3a528c8cd 100644 --- a/crates/cli-support/tests/test_add.rs +++ b/crates/cli-support/tests/test_add.rs @@ -65,6 +65,26 @@ fn test_nodejs_js() { insta::assert_snapshot!(output.js()); } +#[test] +fn test_nodejs_module_start() { + let mut bindgen = Bindgen::new(); + bindgen.nodejs_module(true).unwrap(); + bindgen.input_path(ADD_WASM.concat()); + + let output = bindgen.generate_output().unwrap(); + insta::assert_snapshot!(output.start().unwrap()); +} + +#[test] +fn test_nodejs_module_js() { + let mut bindgen = Bindgen::new(); + bindgen.nodejs_module(true).unwrap(); + bindgen.input_path(ADD_WASM.concat()); + + let output = bindgen.generate_output().unwrap(); + insta::assert_snapshot!(output.js()); +} + #[test] fn test_web_start() { let mut bindgen = Bindgen::new(); diff --git a/crates/cli-support/tests/test_native_add.rs b/crates/cli-support/tests/test_native_add.rs index 4f378492560..228ecced30d 100644 --- a/crates/cli-support/tests/test_native_add.rs +++ b/crates/cli-support/tests/test_native_add.rs @@ -65,6 +65,26 @@ fn test_nodejs_js() { insta::assert_snapshot!(output.js()); } +#[test] +fn test_nodejs_module_start() { + let mut bindgen = Bindgen::new(); + bindgen.nodejs_module(true).unwrap(); + bindgen.input_path(ADD_WASM.concat()); + + let output = bindgen.generate_output().unwrap(); + insta::assert_snapshot!(output.start().unwrap()); +} + +#[test] +fn test_nodejs_module_js() { + let mut bindgen = Bindgen::new(); + bindgen.nodejs_module(true).unwrap(); + bindgen.input_path(ADD_WASM.concat()); + + let output = bindgen.generate_output().unwrap(); + insta::assert_snapshot!(output.js()); +} + #[test] fn test_web_start() { let mut bindgen = Bindgen::new();