create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

react-scripts test does not fail when coverage threshold is not met

Open plummer-flex opened this issue 5 years ago • 4 comments

Describe the bug

Utilizing create-react-app, when running tests,

Did you try recovering your dependencies?

Yes.

Which terms did you search for in User Guide?

Tests. Coverage.

Environment

  System:
    OS: macOS 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: Not Found
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Browsers:
    Chrome: 77.0.3865.120
    Firefox: 69.0.2
    Safari: 13.0.2
  npmPackages:
    react: ^16.8.6 => 16.9.0 
    react-dom: ^16.8.6 => 16.9.0 
    react-scripts: 3.0.1 => 3.0.1 
  npmGlobalPackages:
    create-react-app: 3.0.1

Steps to reproduce

package.json

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "test:coverage": "npm run test -- --coverage --watchAll=false",
  },
  "jest": {
    "collectCoverageFrom": [
      "src/components/**/*.js",
      "src/state/**/*.js",
      "src/templates/**/*.js",
      "src/routes/**/*.js"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": 80
      }
    }
  }

Run test:coverage, the console shows a message that test coverage failed, but the test passes.

Expected behavior

If the code coverage thresholds are not met, the console returns a non-zero response.

Actual behavior

Screen Shot 2019-10-23 at 10 31 06 PM

plummer-flex avatar Oct 24 '19 03:10 plummer-flex

Hi @plummer-flex : Is this open for grabs?

anusha5695 avatar Oct 29 '19 03:10 anusha5695

@anusha5696 what do you mean? To be worked?

plummer-flex avatar Oct 29 '19 03:10 plummer-flex

Hi @plummer-flex, have you found any way to fail the script if coverageThreshold is not matched?

ShivamPatel-India avatar Jun 02 '22 04:06 ShivamPatel-India

fwiw: this is working with Node.js 18, NPM 8, and react-scripts 5.

I'm running tests with coverage using a custom script: react-scripts test --coverage --watchAll=false

sflanker avatar Sep 24 '22 04:09 sflanker