From 09483a1d11e42dcd3226ecf59ff4f95999244fff Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 26 Aug 2022 10:19:17 +0200 Subject: [PATCH] Add remark regarding different coverage providers [skip ci] --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 04126c5d..5e96de2e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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: