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

Fix mistake as test files when run coverage issue. #7506

Merged
merged 3 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
- `[jest-cli]` Fix to set prettierPath via config file ([#7412](https://github.com/facebook/jest/pull/7412))
- `[jest-cli]` Support dashed args ([#7497](https://github.com/facebook/jest/pull/7497))
- `[jest-cli]` Fix to run in band tests if watch mode enable when runInBand arg used ([#7518](https://github.com/facebook/jest/pull/7518))
- `[jest-runtime]` Fix mistake as test files when run coverage issue. ([#7506](https://github.com/facebook/jest/pull/7506))

### Chore & Maintenance

Expand Down
44 changes: 42 additions & 2 deletions packages/jest-runtime/src/__tests__/should_instrument.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('should_instrument', () => {
expect(result).toBe(true);
};

it('when testRegex provided and file is not a test file', () => {
it('when testRegex is provided and file is not a test file', () => {
testShouldInstrument('source_file.js', defaultOptions, {
testRegex: ['.*\\.(test)\\.(js)$'],
});
Expand All @@ -45,6 +45,32 @@ describe('should_instrument', () => {
});
});

it('when testPathIgnorePatterns is provided and file is not a test file', () => {
testShouldInstrument('src/test.js', defaultOptions, {
testPathIgnorePatterns: ['src/'],
});
});

it('when more than one testPathIgnorePatterns is provided and filename is not a test file', () => {
testShouldInstrument('src/test.js', defaultOptions, {
testPathIgnorePatterns: ['test/', 'src/'],
});
});

it('when testRegex and testPathIgnorePatterns are provided and file is not a test file', () => {
testShouldInstrument('src/source_file.js', defaultOptions, {
testPathIgnorePatterns: ['test/'],
testRegex: ['.*\\.(test)\\.(js)$'],
});
});

it('when testMatch and testPathIgnorePatterns are provided and file is not a test file', () => {
testShouldInstrument('src/source_file.js', defaultOptions, {
testMatch: ['**/?(*.)(test).js', '!**/dont/**/*.js'],
testPathIgnorePatterns: ['test/'],
});
});

it('should return true when file is in collectCoverageOnlyFrom when provided', () => {
testShouldInstrument(
'collect/only/from/here.js',
Expand Down Expand Up @@ -119,7 +145,7 @@ describe('should_instrument', () => {
);
});

it('when testRegex provided and filename is a test file', () => {
it('when testRegex is provided and filename is a test file', () => {
testShouldInstrument(defaultFilename, defaultOptions, {
testRegex: ['.*\\.(test)\\.(js)$'],
});
Expand All @@ -137,6 +163,20 @@ describe('should_instrument', () => {
});
});

it('when testRegex and testPathIgnorePatterns are provided and filename is a test file', () => {
testShouldInstrument('test/' + defaultFilename, defaultOptions, {
testPathIgnorePatterns: ['src/'],
testRegex: ['.*\\.(test)\\.(js)$'],
});
});

it('when testMatch and testPathIgnorePatterns are provided and file is a test file', () => {
testShouldInstrument('test/' + defaultFilename, defaultOptions, {
testMatch: ['**/?(*.)(test).js'],
testPathIgnorePatterns: ['src/'],
});
});

it('when file is not in collectCoverageOnlyFrom when provided', () => {
testShouldInstrument(
'source_file.js',
Expand Down
25 changes: 15 additions & 10 deletions packages/jest-runtime/src/should_instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,23 @@ export default function shouldInstrument(
}

if (
config.testRegex &&
config.testRegex.some(regex => new RegExp(regex).test(filename))
!config.testPathIgnorePatterns ||
!config.testPathIgnorePatterns.some(pattern => filename.match(pattern))
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's the same check a bit further down this file: https://github.com/facebook/jest/blob/f38b0c9d17f92f3e0f144087db6264d585bcbeed/packages/jest-runtime/src/should_instrument.js#L79-L84

maybe we can just move it up to this place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee testPathIgnorePatterns vs coveragePathIgnorePatterns, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee
@SimenB

Thank you for your review.

I think that it is determined by testRegex, testMatch and testPathIgnorePatterns whether file is test file or not.

return false;
}
if (
config.testRegex &&
config.testRegex.some(regex => new RegExp(regex).test(filename))
) {
return false;
}

if (
config.testMatch &&
config.testMatch.length &&
micromatch([filename], config.testMatch).length
) {
return false;
if (
config.testMatch &&
config.testMatch.length &&
micromatch([filename], config.testMatch).length
) {
return false;
}
}

if (
Expand Down