Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
plummer-flex opened this issue Oct 24, 2019 · 4 comments
Open

Comments

@plummer-flex
Copy link

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

@anusha5695
Copy link

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

@plummer-flex
Copy link
Author

@anusha5696 what do you mean? To be worked?

@ShivamPatel-India
Copy link

ShivamPatel-India commented Jun 2, 2022

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

@sflanker
Copy link

sflanker commented Sep 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants