From 1270b587196b9fcb74db20fb472029df39be30cb Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Fri, 13 Oct 2017 20:23:29 +0100 Subject: [PATCH] Add jest coverage configuration docs --- packages/react-scripts/template/README.md | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 61f32665867..e8a0b5ec59a 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1374,6 +1374,41 @@ Run `npm test -- --coverage` (note extra `--` in the middle) to include a covera Note that tests run much slower with coverage so it is recommended to run it separately from your normal workflow. +#### Configuration + +The default Jest coverage configuration can be overriden by adding any of the following supported keys to a Jest config in your package.json. + +Supported overrides: + - [`collectCoverageFrom`](https://facebook.github.io/jest/docs/en/configuration.html#collectcoveragefrom-array) + - [`coverageReporters`](https://facebook.github.io/jest/docs/en/configuration.html#coveragereporters-array-string) + - [`coverageThreshold`](https://facebook.github.io/jest/docs/en/configuration.html#coveragethreshold-object) + - [`snapshotSerializers`](https://facebook.github.io/jest/docs/en/configuration.html#snapshotserializers-array-string) + +Example package.json: + +```json +{ + "name": "your-package", + "jest": { + "collectCoverageFrom" : [ + "src/**/*.{js,jsx}", + "!/node_modules/", + "!/path/to/dir/" + ], + "coverageThreshold": { + "global": { + "branches": 90, + "functions": 90, + "lines": 90, + "statements": 90 + } + }, + "coverageReporters": ["text"], + "snapshotSerializers": ["my-serializer-module"] + } +} +``` + ### Continuous Integration By default `npm test` runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called `CI`.