guide: refactor and update testing instructions for contributing

This commit is contained in:
Nick Fitzgerald 2018-08-08 15:33:56 -07:00
parent 5ab3059a45
commit 2fcc74e226
4 changed files with 53 additions and 32 deletions

View File

@ -37,6 +37,7 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- [Contributing](./contributing.md) - [Contributing](./contributing.md)
- [Testing](./testing.md)
- [Internal Design](./design.md) - [Internal Design](./design.md)
- [JS Objects in Rust](./design/js-objects-in-rust.md) - [JS Objects in Rust](./design/js-objects-in-rust.md)
- [Exporting a function to JS](./design/exporting-rust.md) - [Exporting a function to JS](./design/exporting-rust.md)

View File

@ -34,24 +34,3 @@ development.
```shell ```shell
yarn yarn
``` ```
## Running Tests
Finally, you can run the tests with `cargo`:
```shell
cargo test
```
### Headless Browser Tests
Some tests are configured to run in a headless Firefox instance. To run these
tests, you must have Firefox installed. If you have Firefox installed in a
non-default, custom location you can set the `WASM_BINDGEN_FIREFOX_BIN_PATH`
environment variable to the path to your `firefox-bin`.
For example:
```shell
WASM_BINDGEN_FIREFOX_BIN_PATH=/home/fitzgen/firefox/firefox-bin cargo test
```

47
guide/src/testing.md Normal file
View File

@ -0,0 +1,47 @@
# Running `wasm-bindgen`'s Tests
## Wasm Tests on Node and Headless Browsers
These are the largest test suites, and most common to run in day to day
`wasm-bindgen` development. These tests are compiled to Wasm and then run in
Node.js or a headless browser via the WebDriver protocol.
```bash
cargo test --target wasm32-unknown-unknown
```
See [the `wasm-bindgen-test` crate's
`README.md`](https://github.com/rustwasm/wasm-bindgen/blob/master/crates/test/README.md)
for details and configuring which headless browser is used.
## Sanity Tests for `wasm-bindgen` on the Native Host Target
This small test suite just verifies that exported `wasm-bindgen` methods can
still be used on the native host's target.
```
cargo test
```
## The Web IDL Frontend's Tests
```
cargo test -p wasm-bindgen-webidl
```
## The Macro UI Tests
These tests assert that we have reasonable error messages that point to the
right source spans when the `#[wasm_bindgen]` proc-macro is misused.
```
cargo test -p ui-tests
```
## The `js-sys` Tests
See [the `js-sys` testing page](js-sys/testing.html).
## The `web-sys` Tests
See [the `web-sys` testing page](web-sys/testing.html).

View File

@ -5,17 +5,11 @@ You can test the `web-sys` crate by running `cargo test` within the
```sh ```sh
cd wasm-bindgen/crates/web-sys cd wasm-bindgen/crates/web-sys
cargo test
cargo test --target wasm32-unknown-unknown cargo test --target wasm32-unknown-unknown
``` ```
These tests all use a headless browser. See the [*Headless Browser The Wasm tests all run within a headless browser. See [the `wasm-bindgen-test`
Tests* section for details on setup and crate's
configuration.](../contributing.html#headless-browser-tests) `README.md`](https://github.com/rustwasm/wasm-bindgen/blob/master/crates/test/README.md)
for details and configuring which headless browser is used.
## Grouping Tests
Because headless tests can have significant setup and tear down overheads, try
and group tests together. Instead of having a different `#[test]` for every
method on some interface, have a single `#[test]` for the interface and all of
its methods. This will keep the test suite running fast, resulting in better
developer ergonomics and CI turn around times. Thanks!