Skip to content

Commit

Permalink
Document coverage in the guide
Browse files Browse the repository at this point in the history
  • Loading branch information
aDogCalledSpot committed Jan 18, 2024
1 parent e8f74a2 commit f5a7516
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
- [Writing Asynchronous Tests](./wasm-bindgen-test/asynchronous-tests.md)
- [Testing in Headless Browsers](./wasm-bindgen-test/browsers.md)
- [Continuous Integration](./wasm-bindgen-test/continuous-integration.md)
- [Coverage (Experimental)](./wasm-bindgen-test/coverage.md)

- [Contributing to `wasm-bindgen`](./contributing/index.md)
- [Testing](./contributing/testing.md)
Expand Down
30 changes: 30 additions & 0 deletions guide/src/wasm-bindgen-test/coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generating Coverage Data

You can ask the runner to generate coverage data from functions marked as `#[wasm_bindgen_test]` in the `.profraw` format.

<div class="warning">
Coverage is still in an experimental state and may be unreliable and could experience
breaking changes at any time.
</div>

## Enabling the feature

To enable this feature, you need to enable the `"unstable-coverage"` feature in your `wasm-bindgen-test` dependency.

## Generating the data

### `RUSTFLAGS` that need to be present

Make sure you are using `RUSTFLAGS=-Cinstrument-coverage -Zno-profiler-runtime`.

### Arguments to the test runner

If you are using `wasm-pack` to run the tests, refer to the `wasm-pack` documentation.

Otherwise, you can use the following environment variables when [executing the test runner][1] to control the coverage output:

[1]: usage.html#appendix-using-wasm-bindgen-test-without-wasm-pack

- `WASM_BINDGEN_UNSTABLE_TEST_COVERAGE` to generate a single `.profraw` in your current working directory.
- `WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT` to control the file name of the profraw or the directory in which it is placed
- `WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_PREFIX` to add a custom prefix to the profraw files. This can be useful if you're running the tests automatically in succession.

0 comments on commit f5a7516

Please sign in to comment.