From dd750448f14f271491f2738c959ed038c02c78fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 6 Jul 2018 17:08:32 +0200 Subject: [PATCH 1/6] fix: testMatch not working with negatios --- packages/jest-cli/src/SearchSource.js | 3 +-- packages/jest-cli/src/__tests__/SearchSource.test.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 7ea662a8c9bd..57caf26e8506 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -47,8 +47,7 @@ const globsToMatcher = (globs: ?Array) => { return () => true; } - const matchers = globs.map(each => micromatch.matcher(each, {dot: true})); - return path => matchers.some(each => each(path)); + return path => micromatch([path], globs, {dot: true}).length > 0; }; const regexToMatcher = (testRegex: string) => { diff --git a/packages/jest-cli/src/__tests__/SearchSource.test.js b/packages/jest-cli/src/__tests__/SearchSource.test.js index 18b51e287bb1..d513df33d2e4 100644 --- a/packages/jest-cli/src/__tests__/SearchSource.test.js +++ b/packages/jest-cli/src/__tests__/SearchSource.test.js @@ -135,7 +135,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx', 'txt'], name, rootDir, - testMatch: ['**/not-really-a-test.txt'], + testMatch: ['**/not-really-a-test.txt', '!**/do-not-match-me.txt'], testRegex: '', }, {}, From 587789f2c1e71ddd08b931d8742fac250c6f2982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 6 Jul 2018 17:14:35 +0200 Subject: [PATCH 2/6] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index efd456d7db1c..0375a7681c75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - `[jest-cli]` Write configuration to stdout when the option was explicitly passed to Jest ([#6447](https://github.com/facebook/jest/pull/6447)) - `[jest-cli]` Fix regression on non-matching suites ([6657](https://github.com/facebook/jest/pull/6657)) - `[jest-runtime]` Roll back `micromatch` version to prevent regression when matching files ([#6661](https://github.com/facebook/jest/pull/6661)) +- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) ## 23.3.0 From f8f8fe87678a85fc29d7c9b499924944ba47b0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 10 Jul 2018 17:22:42 +0200 Subject: [PATCH 3/6] use {dot: true} for all micromatches --- packages/jest-cli/src/runJest.js | 1 + packages/jest-haste-map/src/haste_fs.js | 2 +- packages/jest-message-util/src/index.js | 2 +- packages/jest-runtime/src/should_instrument.js | 5 +++-- scripts/build.js | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index ae7257900460..533c53d9eb0f 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -176,6 +176,7 @@ export default (async function runJest({ !micromatch( [path.relative(globalConfig.rootDir, filename)], globalConfig.collectCoverageFrom, + {dot: true}, ).length ) { return false; diff --git a/packages/jest-haste-map/src/haste_fs.js b/packages/jest-haste-map/src/haste_fs.js index 5c2bd588bf92..a11080618c55 100644 --- a/packages/jest-haste-map/src/haste_fs.js +++ b/packages/jest-haste-map/src/haste_fs.js @@ -58,7 +58,7 @@ export default class HasteFS { const files = new Set(); for (const file in this._files) { const filePath = root ? path.relative(root, file) : file; - if (micromatch([filePath], globs).length) { + if (micromatch([filePath], globs, {dot: true}).length) { files.add(file); } } diff --git a/packages/jest-message-util/src/index.js b/packages/jest-message-util/src/index.js index 67bd810f795d..76b1db788e4a 100644 --- a/packages/jest-message-util/src/index.js +++ b/packages/jest-message-util/src/index.js @@ -216,7 +216,7 @@ const formatPaths = (config: StackTraceConfig, relativeTestPath, line) => { if ( (config.testMatch && config.testMatch.length && - micromatch(filePath, config.testMatch)) || + micromatch(filePath, config.testMatch, {dot: true})) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); diff --git a/packages/jest-runtime/src/should_instrument.js b/packages/jest-runtime/src/should_instrument.js index 0a663ee56378..78ac5a66c07d 100644 --- a/packages/jest-runtime/src/should_instrument.js +++ b/packages/jest-runtime/src/should_instrument.js @@ -30,7 +30,7 @@ export default function shouldInstrument( if ( config.forceCoverageMatch && config.forceCoverageMatch.length && - micromatch.any(filename, config.forceCoverageMatch) + micromatch.any(filename, config.forceCoverageMatch, {dot: true}) ) { return true; } @@ -42,7 +42,7 @@ export default function shouldInstrument( if ( config.testMatch && config.testMatch.length && - micromatch.any(filename, config.testMatch) + micromatch.any(filename, config.testMatch, {dot: true}) ) { return false; } @@ -63,6 +63,7 @@ export default function shouldInstrument( !micromatch( [path.relative(config.rootDir, filename)], options.collectCoverageFrom, + {dot: true}, ).length ) { return false; diff --git a/scripts/build.js b/scripts/build.js index 2a5f8b77aa91..a44c8b3b2566 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -125,14 +125,14 @@ function buildFile(file, silent) { const destPath = getBuildPath(file, BUILD_DIR); mkdirp.sync(path.dirname(destPath)); - if (micromatch.isMatch(file, IGNORE_PATTERN)) { + if (micromatch.isMatch(file, IGNORE_PATTERN, {dot: true})) { silent || process.stdout.write( chalk.dim(' \u2022 ') + path.relative(PACKAGES_DIR, file) + ' (ignore)\n' ); - } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) { + } else if (!micromatch.isMatch(file, JS_FILES_PATTERN, {dot: true})) { fs.createReadStream(file).pipe(fs.createWriteStream(destPath)); silent || process.stdout.write( From cba90d9fba0c61a93908796531ca3086df56ec17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 10 Jul 2018 18:11:32 +0200 Subject: [PATCH 4/6] Revert "use {dot: true} for all micromatches" This reverts commit 592d50bf9a4bc1f97c742e0141ab60b2d36132f3. --- packages/jest-cli/src/runJest.js | 1 - packages/jest-haste-map/src/haste_fs.js | 2 +- packages/jest-message-util/src/index.js | 2 +- packages/jest-runtime/src/should_instrument.js | 5 ++--- scripts/build.js | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index 533c53d9eb0f..ae7257900460 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -176,7 +176,6 @@ export default (async function runJest({ !micromatch( [path.relative(globalConfig.rootDir, filename)], globalConfig.collectCoverageFrom, - {dot: true}, ).length ) { return false; diff --git a/packages/jest-haste-map/src/haste_fs.js b/packages/jest-haste-map/src/haste_fs.js index a11080618c55..5c2bd588bf92 100644 --- a/packages/jest-haste-map/src/haste_fs.js +++ b/packages/jest-haste-map/src/haste_fs.js @@ -58,7 +58,7 @@ export default class HasteFS { const files = new Set(); for (const file in this._files) { const filePath = root ? path.relative(root, file) : file; - if (micromatch([filePath], globs, {dot: true}).length) { + if (micromatch([filePath], globs).length) { files.add(file); } } diff --git a/packages/jest-message-util/src/index.js b/packages/jest-message-util/src/index.js index 76b1db788e4a..67bd810f795d 100644 --- a/packages/jest-message-util/src/index.js +++ b/packages/jest-message-util/src/index.js @@ -216,7 +216,7 @@ const formatPaths = (config: StackTraceConfig, relativeTestPath, line) => { if ( (config.testMatch && config.testMatch.length && - micromatch(filePath, config.testMatch, {dot: true})) || + micromatch(filePath, config.testMatch)) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); diff --git a/packages/jest-runtime/src/should_instrument.js b/packages/jest-runtime/src/should_instrument.js index 78ac5a66c07d..0a663ee56378 100644 --- a/packages/jest-runtime/src/should_instrument.js +++ b/packages/jest-runtime/src/should_instrument.js @@ -30,7 +30,7 @@ export default function shouldInstrument( if ( config.forceCoverageMatch && config.forceCoverageMatch.length && - micromatch.any(filename, config.forceCoverageMatch, {dot: true}) + micromatch.any(filename, config.forceCoverageMatch) ) { return true; } @@ -42,7 +42,7 @@ export default function shouldInstrument( if ( config.testMatch && config.testMatch.length && - micromatch.any(filename, config.testMatch, {dot: true}) + micromatch.any(filename, config.testMatch) ) { return false; } @@ -63,7 +63,6 @@ export default function shouldInstrument( !micromatch( [path.relative(config.rootDir, filename)], options.collectCoverageFrom, - {dot: true}, ).length ) { return false; diff --git a/scripts/build.js b/scripts/build.js index a44c8b3b2566..2a5f8b77aa91 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -125,14 +125,14 @@ function buildFile(file, silent) { const destPath = getBuildPath(file, BUILD_DIR); mkdirp.sync(path.dirname(destPath)); - if (micromatch.isMatch(file, IGNORE_PATTERN, {dot: true})) { + if (micromatch.isMatch(file, IGNORE_PATTERN)) { silent || process.stdout.write( chalk.dim(' \u2022 ') + path.relative(PACKAGES_DIR, file) + ' (ignore)\n' ); - } else if (!micromatch.isMatch(file, JS_FILES_PATTERN, {dot: true})) { + } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) { fs.createReadStream(file).pipe(fs.createWriteStream(destPath)); silent || process.stdout.write( From 408fbd19a12e34b84c70843782a51d1a9ae6467e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 27 Jul 2018 12:14:17 +0200 Subject: [PATCH 5/6] move changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0375a7681c75..11534f201ed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - `[jest-jasmine2]` Use prettier through `require` instead of `localRequire`. Fixes `matchInlineSnapshot` where prettier dependencies like `path` and `fs` are mocked with `jest.mock`. ([#6776](https://github.com/facebook/jest/pull/6776)) - `[docs]` Fix contributors link ([#6711](https://github.com/facebook/jest/pull/6711)) - `[website]` Fix website versions page to link to correct language ([#6734](https://github.com/facebook/jest/pull/6734)) +- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) ## 23.4.1 @@ -47,7 +48,6 @@ - `[jest-cli]` Write configuration to stdout when the option was explicitly passed to Jest ([#6447](https://github.com/facebook/jest/pull/6447)) - `[jest-cli]` Fix regression on non-matching suites ([6657](https://github.com/facebook/jest/pull/6657)) - `[jest-runtime]` Roll back `micromatch` version to prevent regression when matching files ([#6661](https://github.com/facebook/jest/pull/6661)) -- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) ## 23.3.0 From 24abf792e8b4421a34a9dd34ff1519a65721440f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 7 Aug 2018 22:33:39 +0200 Subject: [PATCH 6/6] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11534f201ed8..a6b775c28300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - `[jest-snapshot` Mark snapshots as obsolete when moved to an inline snapshot ([#6773](https://github.com/facebook/jest/pull/6773)) - `[jest-config]` Fix `--coverage` with `--findRelatedTests` overwriting `collectCoverageFrom` options ([#6736](https://github.com/facebook/jest/pull/6736)) - `[jest-config]` Update default config for testURL from 'about:blank' to 'http://localhost' to address latest JSDOM security warning. ([#6792](https://github.com/facebook/jest/pull/6792)) +- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) ## 23.4.2 @@ -20,7 +21,6 @@ - `[jest-jasmine2]` Use prettier through `require` instead of `localRequire`. Fixes `matchInlineSnapshot` where prettier dependencies like `path` and `fs` are mocked with `jest.mock`. ([#6776](https://github.com/facebook/jest/pull/6776)) - `[docs]` Fix contributors link ([#6711](https://github.com/facebook/jest/pull/6711)) - `[website]` Fix website versions page to link to correct language ([#6734](https://github.com/facebook/jest/pull/6734)) -- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) ## 23.4.1