Skip to content

Commit

Permalink
Add snapshots for nodejs-module target
Browse files Browse the repository at this point in the history
  • Loading branch information
Systemcluster committed Aug 4, 2024
1 parent bf3fade commit 90dfbfe
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 20 additions & 0 deletions crates/cli-support/tests/test_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions crates/cli-support/tests/test_native_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 90dfbfe

Please sign in to comment.