Skip to content

Commit

Permalink
Add remark regarding different coverage providers [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Aug 26, 2022
1 parent df07288 commit 09483a1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -31,6 +31,7 @@ Storybook test runner turns all of your stories into executable tests.
- [The test runner seems flaky and keeps timing out](#the-test-runner-seems-flaky-and-keeps-timing-out)
- [The test runner reports "No tests found" running on a Windows CI](#the-test-runner-reports-no-tests-found-running-on-a-windows-ci)
- [Adding the test runner to other CI environments](#adding-the-test-runner-to-other-ci-environments)
- [Merging test coverage results in wrong coverage](#merging-test-coverage-results-in-wrong-coverage)
- [Future work](#future-work)

## Features
Expand Down Expand Up @@ -369,6 +370,8 @@ Here's an example on how to achieve that:
}
```

> NOTE: If your other tests (e.g. Jest) are using a different coverageProvider than `babel`, you will have issue when merging the coverage files. [More info here](#merging-test-coverage-results-in-wrong-coverage).
## Experimental test hook API

The test runner renders a story and executes its [play function](https://storybook.js.org/docs/react/writing-stories/play-function) if one exists. However, there are certain behaviors that are not possible to achieve via the play function, which executes in the browser. For example, if you want the test runner to take visual snapshots for you, this is something that is possible via Playwright/Jest, but must be executed in Node.
Expand Down Expand Up @@ -535,6 +538,18 @@ env:
As the test runner is based on playwright, depending on your CI setup you might need to use specific docker images or other configuration. In that case, you can refer to the [Playwright CI docs](https://playwright.dev/docs/ci) for more information.
#### Merging test coverage results in wrong coverage
When merging test coverage reports coming from the test runner with reports from other tools (e.g. Jest), it's possible that the end result is not what you expected.
The test runner uses `babel` as coverage provider, which behaves in a certain way when evaluating code coverage. If your other reports happen to use a different coverage provider than `babel`, such as `v8`, they will evaluate the coverage differently. Once merged, the results will likely seem wrong.
Example: in `v8`, import and export lines are counted as coverable pieces of code, however in `babel`, they are not. This impacts the percentage of coverage calculation.
While the test runner does not provide `v8` as an option for coverage provider, it is recommended that you set `coverageProvider: 'babel'` if you can, so that the reports line up as expected and get merged correctly.
For more context, [here's some explanation](https://github.com/facebook/jest/issues/11188#issue-830796941) why `v8` is not a 1:1 replacement for Babel/Istanbul coverage.
## Future work
Future plans involve adding support for the following features:
Expand Down

0 comments on commit 09483a1

Please sign in to comment.