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

Return exit code 1 if coverage threshold requirements are not met #1974

Conversation

lazywithclass
Copy link
Contributor

First of all thanks for this tool!

I'm very new to Jest so please forgive any stupid error or incorrect assumption.
I'm very open to adapt this to the project / community needs, in fact I am trying to understand how to add an integration test for this, any suggestion is more than welcome.

Summary

Whenever the --coverage flag is passed, jest exits with 0 even if the threshold requirements are not met.

Seems like the solution is to determine if a run is successful after onRunComplete is called, because in that function aggregatedResults is populated with the required values.

Test plan

I've written a small POC which has a 100% coverage requirement which is not met.
With the change after you run npm test in this POC you will get 1 as a result from echo $?.

// sum.js
module.exports = (a, b) => a + b;
// __tests__/sum.test.js
test('adds1 +2 to equal3', () => {
  const sum = require('../sum');
  expect(42).toBe(41+1);
});
// package.json
{
  "name": "jest-example",
  "scripts": {
    "test": "/usr/local/lib/node_modules/jest/jest --coverage"
  },
  "jest": {
    "coverageThreshold": {
      "global": {
        "branches": 100,
        "functions": 100,
        "lines": 100,
        "statements": 100
      }
    }
  },
  "devDependencies": {
    "jest": "^16.0.2"
  }
}

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours has expired.

Before we can review or merge your code, we need you to email cla@fb.com with your details so we can update your status.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@codecov-io
Copy link

codecov-io commented Oct 22, 2016

Current coverage is 87.77% (diff: 100%)

Merging #1974 into master will not change coverage

@@             master      #1974   diff @@
==========================================
  Files            38         38          
  Lines          1252       1252          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits           1099       1099          
  Misses          153        153          
  Partials          0          0          

Powered by Codecov. Last update 891ee5a...732d48f

@cpojer cpojer merged commit 402c86e into jestjs:master Oct 24, 2016
@cpojer
Copy link
Member

cpojer commented Oct 24, 2016

thank you!

okonet pushed a commit to okonet/jest that referenced this pull request Nov 11, 2016
…stjs#1974)

* determine if a run is successful after onRunComplete

* Update TestRunner.js
nickpresta pushed a commit to nickpresta/jest that referenced this pull request Nov 15, 2016
…stjs#1974)

* determine if a run is successful after onRunComplete

* Update TestRunner.js
@honzabrecka
Copy link

Seems to be broken after upgrade to 20.0.0.

@cpojer
Copy link
Member

cpojer commented May 8, 2017

@honzabrecka mind opening a new issue?

@honzabrecka
Copy link

@cpojer No problem, here it is #3520

tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
…stjs#1974)

* determine if a run is successful after onRunComplete

* Update TestRunner.js
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants