diff --git a/packages/jest-runtime/src/__tests__/should_instrument.test.js b/packages/jest-runtime/src/__tests__/should_instrument.test.js index 376e8e7d0b4f..55fc037a17c5 100644 --- a/packages/jest-runtime/src/__tests__/should_instrument.test.js +++ b/packages/jest-runtime/src/__tests__/should_instrument.test.js @@ -198,5 +198,19 @@ describe('shouldInstrument', () => { testShouldInstrument(filename, defaultOptions, defaultConfig); }); + + it('if file is in setupFiles', () => { + testShouldInstrument('setupTest.js', defaultOptions, { + setupFiles: ['setupTest.js'], + rootDir: '/', + }); + }); + + it('if file is in setupFilesAfterEnv', () => { + testShouldInstrument('setupTest.js', defaultOptions, { + setupFilesAfterEnv: ['setupTest.js'], + rootDir: '/', + }); + }); }); }); diff --git a/packages/jest-runtime/src/shouldInstrument.js b/packages/jest-runtime/src/shouldInstrument.js index 6717fbea3e52..b625d4b4e8bd 100644 --- a/packages/jest-runtime/src/shouldInstrument.js +++ b/packages/jest-runtime/src/shouldInstrument.js @@ -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; }