Jest finds tests but doesn't collect coverage

The quick fix I said in my comment, using --watchAll instead, eg: react-scripts test --coverage --watchAll.

Just for future reference, I think ideally we should be using --watch, which would only run on changed files, but it gave me the same trouble. I think it's related to this issue '--coverage --watch' should calculate coverage for all files at first iteration and also this issue No coverage when running in watch mode. I'm not sure why it worked for some people and not you, presumably something to do with Git and staging of files.


Not necessarily the solution in the original questioner's case, but i ran into the exact same problem and this was my solution:

I found that when upgrading jest (from 23 to 26) that i had this issue, and the resolution was to run with the --no-cache option. Presumably they changed something about these coverage reports internally such that the cached data was incompatible.


Seems to be working fine on Linux Mint 19.2. I'd suggest changing your jest config to something a bit more flexible:

"jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!<rootDir>/node_modules/"
    ],
    "coverageThreshold": {
      "global": {
        "lines": 90,
        "statements": 90
      }
    }
  }

And then change your package.json test script if you're using npm (with yarn you can just append --coverage, for example: yarn test --coverage; however, with npm, it'll just ignore it). So I'd suggest either doing this:

 "test": "react-scripts test --coverage",

Or, I'd recommend using yarn over npm. To install yarn, use one of the following methods.

Working: enter image description here