Skip to content

Commit

Permalink
Deduplicate snapshot test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Systemcluster committed Aug 8, 2024
1 parent 27f1379 commit 4dd6070
Show file tree
Hide file tree
Showing 16 changed files with 628 additions and 242 deletions.
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 4dd6070

Please sign in to comment.