From f0a8fabe24b81e445e2f56bb84b58db109742297 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 15 Oct 2018 16:43:51 -0400 Subject: [PATCH] Fix should_instrument decision when given negative testMatch pattern --- CHANGELOG.md | 1 + packages/jest-runtime/src/__tests__/should_instrument.test.js | 3 +-- packages/jest-runtime/src/should_instrument.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74882e2ce6b7..4c6d5caaebcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - `[jest-config]` Moved dynamically assigned `cwd` from `jest-cli` to default configuration in `jest-config` ([#7146](https://github.com/facebook/jest/pull/7146)) - `[jest-config]` Fix `getMaxWorkers` on termux ([#7154](https://github.com/facebook/jest/pull/7154)) - `[jest-runtime]` Throw an explicit error if `js` is missing from `moduleFileExtensions` ([#7160](https://github.com/facebook/jest/pull/7160)) +- `[jest-runtime]` Fix missing coverage when using negative glob pattern in `testMatch` ([#7170](https://github.com/facebook/jest/pull/7170)) ### Chore & Maintenance diff --git a/packages/jest-runtime/src/__tests__/should_instrument.test.js b/packages/jest-runtime/src/__tests__/should_instrument.test.js index f1965b05f6c6..a6891c48f15d 100644 --- a/packages/jest-runtime/src/__tests__/should_instrument.test.js +++ b/packages/jest-runtime/src/__tests__/should_instrument.test.js @@ -35,14 +35,13 @@ describe('should_instrument', () => { it('when testMatch is provided and file is not a test file', () => { testShouldInstrument('source_file.js', defaultOptions, { - testMatch: ['**/?(*.)(test).js'], + testMatch: ['**/?(*.)(test).js', '!**/dont/**/*.js'], }); }); it('should return true when file is in collectCoverageOnlyFrom when provided', () => { testShouldInstrument( 'collect/only/from/here.js', - { collectCoverage: true, collectCoverageOnlyFrom: {'collect/only/from/here.js': true}, diff --git a/packages/jest-runtime/src/should_instrument.js b/packages/jest-runtime/src/should_instrument.js index 0a663ee56378..7d9f76e6ee90 100644 --- a/packages/jest-runtime/src/should_instrument.js +++ b/packages/jest-runtime/src/should_instrument.js @@ -42,7 +42,7 @@ export default function shouldInstrument( if ( config.testMatch && config.testMatch.length && - micromatch.any(filename, config.testMatch) + micromatch([filename], config.testMatch).length ) { return false; }