Skip to content

Commit

Permalink
Exclude setup files from coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lekterable committed Feb 3, 2019
1 parent 2780a77 commit 8211398
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/jest-runtime/src/__tests__/should_instrument.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,19 @@ describe('shouldInstrument', () => {

testShouldInstrument(filename, defaultOptions, defaultConfig);
});

it('if file is in setupFiles', () => {
testShouldInstrument('setupTest.js', defaultOptions, {
rootDir: '/',
setupFiles: ['setupTest.js'],
});
});

it('if file is in setupFilesAfterEnv', () => {
testShouldInstrument('setupTest.js', defaultOptions, {
rootDir: '/',
setupFilesAfterEnv: ['setupTest.js'],
});
});
});
});
14 changes: 14 additions & 0 deletions packages/jest-runtime/src/shouldInstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ export default function shouldInstrument(
return false;
}

if (
config.setupFiles &&
config.setupFiles.some(setupFile => setupFile === filename)
) {
return false;
}

if (
config.setupFilesAfterEnv &&
config.setupFilesAfterEnv.some(setupFile => setupFile === filename)
) {
return false;
}

if (MOCKS_PATTERN.test(filename)) {
return false;
}
Expand Down

0 comments on commit 8211398

Please sign in to comment.