Skip to content

guide: Add documentation for testing with wasm-bindgen-test #818

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

Merged
merged 1 commit into from
Sep 12, 2018

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Sep 12, 2018

Fixes #616

Add this to the root of your test crate, e.g. `$MY_CRATE/tests/wasm.rs`:

```rust
wasm_bindgen_test_configure!(run_in_browser);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may want to use use wasm_bindgen_test::wasm_bindgen_test_configure; just above it (to bring the macro into scope)

|
curl --retry 5 -LO https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
export CHROMEDRIVER_ARGS=--verbose
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this shouldn't be required

|
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
source ~/.nvm/nvm.sh
nvm install v10.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't necessarily required actually, the version of node installed automatically on Travis should already have wasm support

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node comes with travis, even for non-node/js projects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so! I could be wrong though, I'd have to check...

curl --retry 5 -LO https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar xf geckodriver-v0.21.0-linux64.tar.gz

INSTALL_CHROMEDRIVER: &INSTALL_CHROMEDRIVER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this yaml syntax it may be best to inline it directly into the install section below to avoid confusing those who don't know about the syntax (which is probably almost everyone)

```

Writing tests is the same as normal Rust `#[test]`s, except we are using the
`#[wasm_bindgen_test]` attribute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good spot to mention pub mod ...

Copy link
Contributor

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have left all those comments as part of a review...

@fitzgen fitzgen force-pushed the guide-wasm-bindgen-test branch from 3b73132 to e2e815a Compare September 12, 2018 22:40
@fitzgen fitzgen merged commit c6ede65 into rustwasm:master Sep 12, 2018
@fitzgen fitzgen deleted the guide-wasm-bindgen-test branch September 12, 2018 22:40

install:
- rustup target add wasm32-unknown-unknown
- cargo install wasm-bindgen-cli
Copy link
Contributor

@chinedufn chinedufn Sep 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd imagine that a bunch of people will just copy this so ideally this would be a fast-enough starting point.

This can take minutes, so could it make sense to instead either:

option 1. Download / decompress a release binary and move it to either ~/.cargo/bin or /usr/local/bin

option 2. Cache cargo deps (I see that the wasm-bindgen repo's travis seems to do this?)

Happy to do either if you think it makes sense!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chinedufn totally -- good call! I think option 1 is more straight forward, and we could also have a comment mentioning something like

Download and unpack the wasm-bindgen CLI tools. Alternatively, use wasm-pack to manage wasm-bindgen binaries for you.

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the guidance!

For posterity #824

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

Successfully merging this pull request may close these issues.

3 participants