Skip to content

Commit

Permalink
Add snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Systemcluster committed Aug 11, 2024
1 parent 031fe89 commit 9fa9520
Show file tree
Hide file tree
Showing 18 changed files with 642 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.webidl linguist-vendored
*.snap linguist-generated
3 changes: 3 additions & 0 deletions crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.92' }
wasm-bindgen-wasm-conventions = { path = '../wasm-conventions', version = '=0.2.92' }
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.92' }
unicode-ident = "1.0.5"

[dev-dependencies]
insta = "1.39.0"
69 changes: 69 additions & 0 deletions crates/cli-support/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#[macro_export]
#[allow(unused)]
macro_rules! test_output_snapshot {
($name:ident, $start_output:literal, $init:expr) => {
#[test]
fn $name() {
use std::path::PathBuf;
use wasm_bindgen_cli_support::Bindgen;

let mut bindgen = Bindgen::new();
$init(&mut bindgen);
bindgen.input_path(WASM.concat());

let output = bindgen.generate_output().unwrap();
let mut settings = insta::Settings::clone_current();
settings.set_snapshot_suffix(
PathBuf::from(WASM[1])
.file_stem()
.unwrap()
.to_str()
.unwrap(),
);
settings.set_prepend_module_to_snapshot(false);
if $start_output {
settings.bind(|| insta::assert_snapshot!(output.start().unwrap()));
} else {
settings.bind(|| insta::assert_snapshot!(output.js()));
}
}
};
}
#[macro_export]
#[allow(unused)]
macro_rules! test_output_empty {
($name:ident, $start_output:literal, $init:expr) => {
#[test]
fn $name() {
use wasm_bindgen_cli_support::Bindgen;

let mut bindgen = Bindgen::new();
$init(&mut bindgen);
bindgen.input_path(WASM.concat());

let output = bindgen.generate_output().unwrap();
if $start_output {
assert!(output.start().is_none());
} else {
assert!(output.js().is_empty());
}
}
};
}
#[macro_export]
#[allow(unused)]
macro_rules! test_output_error {
($name:ident, $init:expr) => {
#[test]
fn $name() {
use wasm_bindgen_cli_support::Bindgen;

let mut bindgen = Bindgen::new();
$init(&mut bindgen);
bindgen.input_path(WASM.concat());

let output = bindgen.generate_output();
assert!(output.is_err());
}
};
}
8 changes: 8 additions & 0 deletions crates/cli-support/tests/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/cli-support/tests/snapshots/bundler_js@native_add.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions crates/cli-support/tests/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions crates/cli-support/tests/snapshots/deno_js@native_add.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions crates/cli-support/tests/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions crates/cli-support/tests/snapshots/nodejs_js@native_add.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/cli-support/tests/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions crates/cli-support/tests/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 111 additions & 0 deletions crates/cli-support/tests/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9fa9520

Please sign in to comment.