Skip to content

Commit

Permalink
Only print cargo test output the once
Browse files Browse the repository at this point in the history
Also introduces testing of our CLI's output via `assert_cmd`. Expect some follow
ups to get more of our testing infrastructure using this incredible crate!

Fixes #511
  • Loading branch information
fitzgen authored and ashleygwilliams committed Feb 27, 2019
1 parent e5c48c2 commit 4a7cd6a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
14 changes: 0 additions & 14 deletions Cargo.lock

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

40 changes: 40 additions & 0 deletions tests/all/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,43 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() {
err.matches("YABBA DABBA DOO").count() == log_cnt * 2
}));
}

#[test]
fn test_output_is_printed_once() {
let fixture = fixture::Fixture::new();
fixture
.readme()
.cargo_toml("wbg-test-node")
.hello_world_src_lib()
.file(
"tests/node.rs",
r#"
extern crate wasm_bindgen;
extern crate wasm_bindgen_test;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen_test]
fn pass() {
log("YABBA DABBA DOO");
assert_eq!(1, 2);
}
"#,
);

fixture
.wasm_pack()
.arg("test")
.arg("--node")
.assert()
.stderr(predicate::function(|err: &str| {
err.matches("YABBA DABBA DOO").count() == 1
}))
.failure();
}
10 changes: 10 additions & 0 deletions tests/all/utils/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ impl Fixture {
cmd
}

/// Get a `wasm-pack` command configured to run in this fixure's temp
/// directory and using the test cache.
pub fn wasm_pack(&self) -> Command {
use assert_cmd::prelude::*;
let mut cmd = Command::main_binary().unwrap();
cmd.current_dir(&self.path);
cmd.env("WASM_PACK_CACHE", self.cache_dir());
cmd
}

pub fn lock(&self) -> MutexGuard<'static, ()> {
use std::sync::Mutex;
lazy_static! {
Expand Down

0 comments on commit 4a7cd6a

Please sign in to comment.