From 79f370deef035949f15bbd5e9d0b10267271a841 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Apr 2019 08:02:27 -0700 Subject: [PATCH] Add env vars to filter `wasm-bindgen-test-runner` tests This is intended to handle #1458 and #822. These issues stem from behavior where: wasm-pack test --node will actually run both Node.js and browser tests! Two new env vars are read here, `WASM_BINDGEN_TEST_ONLY_{NODE,WEB}`, which control which tests are executed by `wasm-bindgen-test-runner`. The intention is that these will be set by `wasm-pack` to configure which tests are run, and if test suites are skipped due to the env vars we'll print an informational message indicating how they can be run. Closes #822 Closes #1458 --- .../src/bin/wasm-bindgen-test-runner/main.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs index 38f179fb..3703c83e 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs @@ -103,6 +103,30 @@ fn rmain() -> Result<(), Error> { let headless = env::var("NO_HEADLESS").is_err(); let debug = env::var("WASM_BINDGEN_NO_DEBUG").is_err(); + // Gracefully handle requests to execute only node or only web tests. + if env::var_os("WASM_BINDGEN_TEST_ONLY_NODE").is_some() { + if !node { + println!("this test suite is only configured to run in a browser, \ + but we're only testing node.js tests so skipping"); + return Ok(()); + } + } + if env::var_os("WASM_BINDGEN_TEST_ONLY_WEB").is_some() { + if node { + println!("\ +This test suite is only configured to run in node.js, but we're only running +browser tests so skipping. If you'd like to run the tests in a browser +include this in your crate when testing: + + wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + +You'll likely want to put that in a `#[cfg(test)]` module or at the top of an +integration test.\ +"); + return Ok(()); + } + } + // Make the generated bindings available for the tests to execute against. shell.status("Executing bindgen..."); let mut b = Bindgen::new();