Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run specific tests during wasm-pack test #630

Merged
merged 1 commit into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions docs/src/commands/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,30 @@ $ tree crates/foo
│   ├── lib.rs
└── tests
├── diff_patch.rs
   └── node.rs
```

```
# Run all tests in tests/diff_patch.rs
wasm-pack test crates/foo --firefox --headless -- --tests diff_patch
# Run all tests in tests/diff_patch.rs in Firefox
wasm-pack test crates/foo --firefox --headless -- --test diff_patch

# Run all tests in tests/diff_patch.rs that contain the word "replace"
wasm-pack test crates/foo --firefox --headless -- --tests diff_patch replace
wasm-pack test crates/foo --firefox --headless -- --test diff_patch replace

# Run all tests inside of a `tests` module inside of src/lib/diff.rs
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests

# Same as the above, but only if they contain the word replace
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests::replace
```

Note that you can also filter tests by location in which they're supposed to
run. For example:

```
# Run all tests which are intended to execute in Node.js
wasm-pack test --node

# Run all tests which are intended to be executed in a browser
wasm-pack test --firefox --headless
```
70 changes: 22 additions & 48 deletions src/command/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,13 @@ impl Test {
test::cargo_test_wasm(
&self.crate_path,
self.release,
Some((
"CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER",
&self.test_runner_path.as_ref().unwrap(),
)),
vec![
(
"CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER",
&**self.test_runner_path.as_ref().unwrap(),
),
("WASM_BINDGEN_TEST_ONLY_NODE", "1".as_ref()),
],
&self.extra_options,
)?;
info!("Finished running tests in node.");
Expand All @@ -326,22 +329,8 @@ impl Test {
chromedriver
);

let test_runner = self
.test_runner_path
.as_ref()
.unwrap()
.display()
.to_string();
let test_runner = test_runner.as_str();
info!("Using wasm-bindgen test runner at {}", test_runner);

let mut envs = vec![
("CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER", test_runner),
("CHROMEDRIVER", chromedriver),
];
if !self.headless {
envs.push(("NO_HEADLESS", "1"));
}
let mut envs = self.webdriver_env();
envs.push(("CHROMEDRIVER", chromedriver));

test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(())
Expand All @@ -365,22 +354,8 @@ impl Test {
geckodriver
);

let test_runner = self
.test_runner_path
.as_ref()
.unwrap()
.display()
.to_string();
let test_runner = test_runner.as_str();
info!("Using wasm-bindgen test runner at {}", test_runner);

let mut envs = vec![
("CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER", test_runner),
("GECKODRIVER", geckodriver),
];
if !self.headless {
envs.push(("NO_HEADLESS", "1"));
}
let mut envs = self.webdriver_env();
envs.push(("GECKODRIVER", geckodriver));

test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(())
Expand All @@ -401,24 +376,23 @@ impl Test {
safaridriver
);

let test_runner = self
.test_runner_path
.as_ref()
.unwrap()
.display()
.to_string();
let test_runner = test_runner.as_str();
info!("Using wasm-bindgen test runner at {}", test_runner);
let mut envs = self.webdriver_env();
envs.push(("SAFARIDRIVER", safaridriver));

test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(())
}

fn webdriver_env(&self) -> Vec<(&'static str, &str)> {
let test_runner = self.test_runner_path.as_ref().unwrap().to_str().unwrap();
info!("Using wasm-bindgen test runner at {}", test_runner);
let mut envs = vec![
("CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER", test_runner),
("SAFARIDRIVER", safaridriver),
("WASM_BINDGEN_TEST_ONLY_WEB", "1"),
];
if !self.headless {
envs.push(("NO_HEADLESS", "1"));
}

test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(())
return envs;
}
}