create-react-app: test coverage is empty - v3.0.0

Is this a bug report?

yes, test coverage is always empty

After updating react-scripts to 3.0.0 test coverage is always empty, this worked before in v2.1.8


v2.1.8

Screenshot 2019-04-24 at 16 17 37

v3.0.0

Screenshot 2019-04-24 at 16 19 22

Did you try recovering your dependencies?

This happens after booting an app up using create react app using typescript create-react-app cra-coverage-example --typescript

Which terms did you search for in User Guide?

n/a

Environment

Environment Info:

  System:
    OS: macOS 10.14.4
    CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 11.12.0 - ~/.nvm/versions/node/v11.12.0/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.12.0/bin/npm
  Browsers:
    Chrome: 73.0.3683.103
    Safari: 12.1
  npmPackages:
    react: ^16.8.6 => 16.8.6
    react-dom: ^16.8.6 => 16.8.6
    react-scripts: 3.0.0 => 3.0.0
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

  1. create-react-app cra-coverage-example --typescript
  2. yarn test --coverage

Expected Behavior

test coverage would be output

Actual Behavior

test coverage is always empty

Reproducible Demo

https://github.com/pete-redmond-cko/cra-coverage-example or you can spin up an app using create react app v.3.0.0 and run yarn test --coverage

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 19
  • Comments: 39 (2 by maintainers)

Commits related to this issue

Most upvoted comments

If you turn off watch via: yarn test --coverage --watchAll=false

It will work properly. Looks like a Jest bug. @stipsan

Jest needs more Jest tests to test the Jest.

try this one

npm run test -- --coverage --watchAll=false

If you turn off watch via: yarn test --coverage --watchAll=false

It will work properly. Looks like a Jest bug. @stipsan

It doesn’t fix it for me though. Still getting empty results image

At this point, I haven’t seen a legit bug except for in a minor case (pressing ‘a’ in watch mode doesn’t retroactive show coverage). In all cases the feature is working as expected. If you disagree, please file a new issue with a clean repro so we can investigate. Thanks!

@sketchbuch For npm, you’ll need an extra set of dashes to get watchAll flag to work, something like: npm run test:c -- --watchAll=false, which produces result:

-----------------------------------------|----------|----------|----------|----------|-------------------|
File                                     |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------------------------------------|----------|----------|----------|----------|-------------------|
All files                                |    56.75 |    47.32 |    47.87 |    57.32 |                   |
 src                                     |        0 |        0 |        0 |        0 |                   |
  index.js                               |        0 |      100 |      100 |        0 |                10 |
  registerServiceWorker.js               |        0 |        0 |        0 |        0 |... 87,91,96,97,98 |
 src/js/actions                          |    98.16 |    81.82 |    98.68 |    98.16 |                   |
  appActions.js                          |      100 |      100 |      100 |      100 |                   |
  builderActions.js                      |      100 |      100 |      100 |      100 |                   |
  categoryActions.js                     |      100 |      100 |      100 |      100 |                   |
  classActions.js                        |      100 |      100 |      100 |      100 |                   |
  dataActions.js                         |      100 |      100 |      100 |      100 |                   |

Here I’ve changed one file, and the coverage also works correctly:

git diff
diff --git a/src/js/actions/appActions.js b/src/js/actions/appActions.js
index 225a476..a5513a5 100644
--- a/src/js/actions/appActions.js
+++ b/src/js/actions/appActions.js
@@ -1,4 +1,5 @@
 // @flow
+console.log('foo');
 
 import { APP_ERRORED, APP_LOADED } from '../constants/actionTypes';
 import type { ActionCreator } from '../types/action';

 PASS  src/js/actions/tests/appActions.test.js
  ● Console

    console.log src/js/actions/appActions.js:2
      foo

 PASS  src/js/components/App/App.test.js
  ● Console

    console.log src/js/actions/appActions.js:2
      foo

---------------|----------|----------|----------|----------|-------------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files      |      100 |      100 |      100 |      100 |                   |
 appActions.js |      100 |      100 |      100 |      100 |                   |
---------------|----------|----------|----------|----------|-------------------|

Test Suites: 2 passed, 2 total
Tests:       5 passed, 5 total
Snapshots:   0 total
Time:        3.256s, estimated 6s
Ran all test suites related to changed files.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press q to quit watch mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press Enter to trigger a test run.

I have the same problem (v3.0.1). I can’t run coverage at all. It used to work, this is my repo: https://github.com/sketchbuch/school-report

when I run > npm run test:c

it says no tests have changed. --watchAll or --watchAll=false does nothing. Pressing “a” runs the tests but produces no coverage or even runs coverage. The coverage folder is created but contains just a few files - mostly little images used in the report display.