Skip to content

Conversation

@jebentier
Copy link

@jebentier jebentier commented Oct 7, 2019

Summary

Fixes: #8474

This PR is adding a new flag (--passWithNoCoverage) that can be passed when running jest with code coverage in combination with coverageThreshold. This flag makes tests not fail when there is are coverageThresholds set for a specific file, and a subset of tests are run with coverage that do not touch all files specified in the coverageThreshold configuration.

Test plan

An end to end test was added with this PR that demonstrates the expected behavior of the flag. The following configuration of files, tests, and configuration will now pass when jest is executed with the --passWithNoCoverage flag.

package.json

jest: {
  collectCoverage: true,
  collectCoverageFrom: ['**/*.js'],
  coverageThreshold: {
    global: {
      lines: 100
    },
    'pear.js': {
      lines: 100
    }
  }
}

grape.js

module.exports = () => {
  return 1 + 2;
};

grape.test.js

const grape = require('../grape.js');
test('grape', () => expect(grape()).toBe(3));

jest run command

$> jest --coverage --passWithNoCoverage
PASS __tests__/grape.test.js
  ✓ grape

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |      100 |      100 |      100 |                   |
 grape.js |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1s
Ran all test suites.
$> echo $?
0

@jebentier jebentier changed the title Add cli flag pass with no coverage (https://github.com/facebook/jest/issues/8474) Add cli flag --passWithNoCoverage Oct 7, 2019
@thymikee
Copy link
Contributor

thymikee commented Oct 8, 2019

Hey! Thanks for sending the PR. We're trying hard to not introduce new config options, when it can be built on top of existing ones. And this feature request wasn't properly discussed. Have you considered running with --no-coverage at all?

@thymikee
Copy link
Contributor

thymikee commented Oct 8, 2019

Let's close it and go back to the original issue to properly discuss it :)

@thymikee thymikee closed this Oct 8, 2019
@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 11, 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.

Do not fail on 'Jest: Coverage data for ... was not found.' or make coverageThreshold configurable on the cli

3 participants