Skip to content

How to run actual unit tests on headless browser? #742

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

Closed
pepsighan opened this issue Aug 21, 2018 · 7 comments
Closed

How to run actual unit tests on headless browser? #742

pepsighan opened this issue Aug 21, 2018 · 7 comments

Comments

@pepsighan
Copy link
Member

Currently, as I have tried, we can only run integration tests with the help of wasm-bindgen-test-runner.
Is there a way to run such tests from within the module itself?

@limira
Copy link
Contributor

limira commented Aug 21, 2018

How about this?

#[cfg(test)]
extern crate wasm_bindgen_test;
#[cfg(test)]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

In a mod:

#[cfg(test)]
use wasm_bindgen_test::*;
//....
#[cfg(test)]
#[wasm_bindgen_test]
fn test_on_web() {
    let div = document.create_element("div");
    assert_eq!(div.tag_name(), "DIV");
    assert_eq!(1 + 1, 2);
}

I think I successfully run test with this setup! The output is:

Running headless tests in Chrome with `...`
running 1 test                                    

test simi::app::test_on_web ... ok

@alexcrichton
Copy link
Contributor

Indeed @limira's instructions should do the trick! @csharad does that answer what you were thinking?

@pepsighan
Copy link
Member Author

Thanks @limira. I was able to run the tests in the lib.rs itself, YAY!. But not in the nested modules.
I have it in the repo. How were you able to run it inside the mod? What am I doing wrong?

@pepsighan
Copy link
Member Author

Wait a minute! I know the problem now. It seems the tests are only runnable if the module itself is visible to lib.rs. Weird as the normal tests are runnable without their module being pub.

@limira
Copy link
Contributor

limira commented Aug 22, 2018

So, I was in luck because I put it in a pub mod. I think it must be pub because tests are actually run on the JS side.

@alexcrichton
Copy link
Contributor

Ah yes unfortunately pub mod is required for submodules to run tests. That's due to #201

@pepsighan
Copy link
Member Author

I'll close it then as my issue is ironed out. Thank you both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants