From d891b862178137ea89a6dba51ef687a91565d5f7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 19 Aug 2019 12:47:26 +0200 Subject: [PATCH 1/5] chore: upgrade to micromatch v4 --- CHANGELOG.md | 1 + package.json | 2 +- packages/jest-config/package.json | 2 +- packages/jest-core/package.json | 2 +- packages/jest-haste-map/package.json | 4 ++-- packages/jest-message-util/package.json | 2 +- packages/jest-transform/package.json | 2 +- yarn.lock | 14 +++++++++++--- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b9f8e831c60..799d7d4e7437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[*]` [**BREAKING**] Drop support for Node 6 ([#8455](https://github.com/facebook/jest/pull/8455)) - `[*]` Add Node 12 to CI ([#8411](https://github.com/facebook/jest/pull/8411)) +- `[*]` [**BREAKING**] Upgrade to Micromatch v4 ([#8852](https://github.com/facebook/jest/pull/8852)) - `[docs]` Fix broken link pointing to legacy JS file in "Snapshot Testing". - `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM from v11 to v15 ([#8851](https://github.com/facebook/jest/pull/8851)) diff --git a/package.json b/package.json index 0c7f692bc3f4..9bff104d6ca1 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "karma-webpack": "4.0.0-rc.5", "left-pad": "^1.1.1", "lerna": "3.15.0", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "mkdirp": "^0.5.1", "mocha": "^6.0.2", "mock-fs": "^4.4.1", diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index cc0e89847a7a..b6ce70c9e922 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -24,7 +24,7 @@ "jest-resolve": "^24.9.0", "jest-util": "^24.9.0", "jest-validate": "^24.9.0", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "pretty-format": "^24.9.0", "realpath-native": "^1.1.0" }, diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index ccd64e4211de..2326465cf78c 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -27,7 +27,7 @@ "jest-util": "^24.9.0", "jest-validate": "^24.9.0", "jest-watcher": "^24.9.0", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "p-each-series": "^1.0.0", "realpath-native": "^1.1.0", "rimraf": "^2.5.4", diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index a0cdef2e1103..a2a28d77e683 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -11,14 +11,14 @@ "types": "build/index.d.ts", "dependencies": { "@jest/types": "^24.9.0", - "anymatch": "^2.0.0", + "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", "graceful-fs": "^4.1.15", "invariant": "^2.2.4", "jest-serializer": "^24.9.0", "jest-util": "^24.9.0", "jest-worker": "^24.9.0", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "sane": "^4.0.3", "walker": "^1.0.7" }, diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index 2ed953661829..b3f9c25ba3d1 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -18,7 +18,7 @@ "@jest/types": "^24.9.0", "@types/stack-utils": "^1.0.1", "chalk": "^2.0.1", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "slash": "^2.0.0", "stack-utils": "^1.0.1" }, diff --git a/packages/jest-transform/package.json b/packages/jest-transform/package.json index 1d9707b52dd0..7ee7cbebce6f 100644 --- a/packages/jest-transform/package.json +++ b/packages/jest-transform/package.json @@ -19,7 +19,7 @@ "jest-haste-map": "^24.9.0", "jest-regex-util": "^24.9.0", "jest-util": "^24.9.0", - "micromatch": "^3.1.10", + "micromatch": "^4.0.2", "pirates": "^4.0.1", "realpath-native": "^1.1.0", "slash": "^2.0.0", diff --git a/yarn.lock b/yarn.lock index 0045a318e4d7..42a12e1944ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3009,7 +3009,7 @@ anymatch@^2.0.0: micromatch "^3.1.4" normalize-path "^2.1.1" -anymatch@^3.0.1: +anymatch@^3.0.1, anymatch@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.0.3.tgz#2fb624fe0e84bccab00afee3d0006ed310f22f09" integrity sha512-c6IvoeBECQlMVuYUjSwimnhmztImpErfxJzWZhIQinIvQWoGOnB0dLIgifbPHQt5heS6mNlaZG16f06H3C8t1g== @@ -3728,7 +3728,7 @@ braces@^2.3.1, braces@^2.3.2: split-string "^3.0.2" to-regex "^3.0.1" -braces@^3.0.2: +braces@^3.0.1, braces@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -9614,6 +9614,14 @@ micromatch@^3.1.10, micromatch@^3.1.4, micromatch@^3.1.8: snapdragon "^0.8.1" to-regex "^3.0.2" +micromatch@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.2.tgz#4fcb0999bf9fbc2fcbdd212f6d629b9a56c39259" + integrity sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q== + dependencies: + braces "^3.0.1" + picomatch "^2.0.5" + miller-rabin@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d" @@ -10864,7 +10872,7 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= -picomatch@^2.0.4: +picomatch@^2.0.4, picomatch@^2.0.5: version "2.0.7" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.0.7.tgz#514169d8c7cd0bdbeecc8a2609e34a7163de69f6" integrity sha512-oLHIdio3tZ0qH76NybpeneBhYVj0QFTfXEFTc/B3zKQspYfYYkWYgFsmzo+4kvId/bQRcNkVeguI3y+CD22BtA== From bee422bfdef16723f2056f3f03230b527fc8aaf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 19 Aug 2019 16:30:58 +0200 Subject: [PATCH 2/5] fix anymatch namespace issue --- packages/jest-haste-map/src/lib/FSEventsWatcher.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 815020474a29..1dc6826fe81d 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -9,7 +9,7 @@ import * as fs from 'fs'; import * as path from 'path'; import {EventEmitter} from 'events'; -import anymatch from 'anymatch'; +import anymatch, {Matcher} from 'anymatch'; import {some as micromatchSome} from 'micromatch'; // eslint-disable-next-line import {Watcher} from 'fsevents'; @@ -40,7 +40,7 @@ type FsEventsWatcherEvent = */ class FSEventsWatcher extends EventEmitter { public readonly root: string; - public readonly ignored?: anymatch.Matcher; + public readonly ignored?: Matcher; public readonly glob: Array; public readonly dot: boolean; public readonly hasIgnore: boolean; @@ -65,7 +65,7 @@ class FSEventsWatcher extends EventEmitter { fileCallback: (normalizedPath: string, stats: fs.Stats) => void, endCallback: Function, errorCallback: Function, - ignored?: anymatch.Matcher, + ignored?: Matcher, ) { walker(dir) .filterDir( @@ -83,7 +83,7 @@ class FSEventsWatcher extends EventEmitter { dir: string, opts: { root: string; - ignored?: anymatch.Matcher; + ignored?: Matcher; glob: string | Array; dot: boolean; }, From 8837cf169f8241bf03a051e6ec2204631c5ebf42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 19 Aug 2019 20:43:15 +0200 Subject: [PATCH 3/5] use match instead of some --- packages/jest-config/src/normalize.ts | 8 ++++---- packages/jest-core/src/SearchSource.ts | 4 ++-- packages/jest-haste-map/src/HasteFS.ts | 4 ++-- packages/jest-haste-map/src/lib/FSEventsWatcher.ts | 6 +++--- packages/jest-message-util/src/index.ts | 4 ++-- packages/jest-transform/src/shouldInstrument.ts | 12 +++++++----- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index bc798f9bac3a..010dcbac1aba 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -12,7 +12,7 @@ import {Config} from '@jest/types'; import {ValidationError, validate} from 'jest-validate'; import {clearLine, replacePathSepForGlob} from 'jest-util'; import chalk from 'chalk'; -import {some as micromatchSome} from 'micromatch'; +import micromatch from 'micromatch'; import {sync as realpath} from 'realpath-native'; import Resolver from 'jest-resolve'; import {replacePathSepForRegex} from 'jest-regex-util'; @@ -982,10 +982,10 @@ export default function normalize( if (newOptions.collectCoverageFrom) { collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => { if ( - !micromatchSome( - replacePathSepForGlob(path.relative(options.rootDir, filename)), + !micromatch( + [replacePathSepForGlob(path.relative(options.rootDir, filename))], newOptions.collectCoverageFrom!, - ) + ).length ) { return patterns; } diff --git a/packages/jest-core/src/SearchSource.ts b/packages/jest-core/src/SearchSource.ts index 4159137df91b..f1ef516300dc 100644 --- a/packages/jest-core/src/SearchSource.ts +++ b/packages/jest-core/src/SearchSource.ts @@ -6,7 +6,7 @@ */ import * as path from 'path'; -import {some as micromatchSome} from 'micromatch'; +import micromatch from 'micromatch'; import {Context} from 'jest-runtime'; import {Config} from '@jest/types'; import {Test} from 'jest-runner'; @@ -37,7 +37,7 @@ export type TestSelectionConfig = { }; const globsToMatcher = (globs: Array) => (path: Config.Path) => - micromatchSome(replacePathSepForGlob(path), globs, {dot: true}); + !!micromatch([replacePathSepForGlob(path)], globs, {dot: true}).length; const regexToMatcher = (testRegex: Array) => (path: Config.Path) => testRegex.some(testRegex => new RegExp(testRegex).test(path)); diff --git a/packages/jest-haste-map/src/HasteFS.ts b/packages/jest-haste-map/src/HasteFS.ts index 1f92658b3ddf..036a652a8d19 100644 --- a/packages/jest-haste-map/src/HasteFS.ts +++ b/packages/jest-haste-map/src/HasteFS.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {some as micromatchSome} from 'micromatch'; +import micromatch from 'micromatch'; import {replacePathSepForGlob} from 'jest-util'; import {Config} from '@jest/types'; import {FileData} from './types'; @@ -86,7 +86,7 @@ export default class HasteFS { const files = new Set(); for (const file of this.getAbsoluteFileIterator()) { const filePath = root ? fastPath.relative(root, file) : file; - if (micromatchSome(replacePathSepForGlob(filePath), globs)) { + if (micromatch([replacePathSepForGlob(filePath)], globs).length) { files.add(file); } } diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 1dc6826fe81d..f3fb0ab5e592 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -10,7 +10,7 @@ import * as fs from 'fs'; import * as path from 'path'; import {EventEmitter} from 'events'; import anymatch, {Matcher} from 'anymatch'; -import {some as micromatchSome} from 'micromatch'; +import micromatch from 'micromatch'; // eslint-disable-next-line import {Watcher} from 'fsevents'; // @ts-ignore no types @@ -139,8 +139,8 @@ class FSEventsWatcher extends EventEmitter { return false; } return this.glob.length - ? micromatchSome(relativePath, this.glob, {dot: this.dot}) - : this.dot || micromatchSome(relativePath, '**/*'); + ? !!micromatch([relativePath], this.glob, {dot: this.dot}).length + : !!this.dot || micromatch([relativePath], '**/*').length; } private handleEvent(filepath: string) { diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index 133c7abc0180..de2a2fb6538e 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -10,7 +10,7 @@ import * as path from 'path'; import {Config} from '@jest/types'; import {AssertionResult, SerializableError} from '@jest/test-result'; import chalk from 'chalk'; -import {some as micromatchSome} from 'micromatch'; +import micromatch from 'micromatch'; import slash from 'slash'; import {codeFrameColumns} from '@babel/code-frame'; import StackUtils from 'stack-utils'; @@ -216,7 +216,7 @@ const formatPaths = ( if ( (config.testMatch && config.testMatch.length && - micromatchSome(filePath, config.testMatch)) || + micromatch([filePath], config.testMatch).length) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); diff --git a/packages/jest-transform/src/shouldInstrument.ts b/packages/jest-transform/src/shouldInstrument.ts index bf38e514e84c..90cef21dd0c6 100644 --- a/packages/jest-transform/src/shouldInstrument.ts +++ b/packages/jest-transform/src/shouldInstrument.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import {Config} from '@jest/types'; import {escapePathForRegex} from 'jest-regex-util'; import {replacePathSepForGlob} from 'jest-util'; -import {any as micromatchAny, some as micromatchSome} from 'micromatch'; +import micromatch, {any as micromatchAny} from 'micromatch'; import {ShouldInstrumentOptions} from './types'; const MOCKS_PATTERN = new RegExp( @@ -39,7 +39,9 @@ export default function shouldInstrument( return false; } - if (micromatchSome(replacePathSepForGlob(filename), config.testMatch)) { + if ( + micromatch([replacePathSepForGlob(filename)], config.testMatch).length + ) { return false; } } @@ -57,10 +59,10 @@ export default function shouldInstrument( // still cover if `only` is specified !options.collectCoverageOnlyFrom && options.collectCoverageFrom && - !micromatchSome( - replacePathSepForGlob(path.relative(config.rootDir, filename)), + !micromatch( + [replacePathSepForGlob(path.relative(config.rootDir, filename))], options.collectCoverageFrom, - ) + ).length ) { return false; } From 1283cf9d455e7584cb3ced5bf65e0f0c3dd4cc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 19 Aug 2019 21:10:48 +0200 Subject: [PATCH 4/5] add explicit check for length 0 --- packages/jest-config/src/normalize.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 010dcbac1aba..152416b30355 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -982,10 +982,10 @@ export default function normalize( if (newOptions.collectCoverageFrom) { collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => { if ( - !micromatch( + micromatch( [replacePathSepForGlob(path.relative(options.rootDir, filename))], newOptions.collectCoverageFrom!, - ).length + ).length === 0 ) { return patterns; } From 2da93b4b87f6875091f133e5162c33f417858f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 19 Aug 2019 21:17:25 +0200 Subject: [PATCH 5/5] more length boolean checks --- packages/jest-core/src/SearchSource.ts | 2 +- packages/jest-haste-map/src/HasteFS.ts | 2 +- packages/jest-haste-map/src/lib/FSEventsWatcher.ts | 4 ++-- packages/jest-message-util/src/index.ts | 2 +- packages/jest-transform/src/shouldInstrument.ts | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/jest-core/src/SearchSource.ts b/packages/jest-core/src/SearchSource.ts index f1ef516300dc..e360c105ffbd 100644 --- a/packages/jest-core/src/SearchSource.ts +++ b/packages/jest-core/src/SearchSource.ts @@ -37,7 +37,7 @@ export type TestSelectionConfig = { }; const globsToMatcher = (globs: Array) => (path: Config.Path) => - !!micromatch([replacePathSepForGlob(path)], globs, {dot: true}).length; + micromatch([replacePathSepForGlob(path)], globs, {dot: true}).length > 0; const regexToMatcher = (testRegex: Array) => (path: Config.Path) => testRegex.some(testRegex => new RegExp(testRegex).test(path)); diff --git a/packages/jest-haste-map/src/HasteFS.ts b/packages/jest-haste-map/src/HasteFS.ts index 036a652a8d19..6a85b1b60100 100644 --- a/packages/jest-haste-map/src/HasteFS.ts +++ b/packages/jest-haste-map/src/HasteFS.ts @@ -86,7 +86,7 @@ export default class HasteFS { const files = new Set(); for (const file of this.getAbsoluteFileIterator()) { const filePath = root ? fastPath.relative(root, file) : file; - if (micromatch([replacePathSepForGlob(filePath)], globs).length) { + if (micromatch([replacePathSepForGlob(filePath)], globs).length > 0) { files.add(file); } } diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index f3fb0ab5e592..a2574a45e0f5 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -139,8 +139,8 @@ class FSEventsWatcher extends EventEmitter { return false; } return this.glob.length - ? !!micromatch([relativePath], this.glob, {dot: this.dot}).length - : !!this.dot || micromatch([relativePath], '**/*').length; + ? micromatch([relativePath], this.glob, {dot: this.dot}).length > 0 + : this.dot || micromatch([relativePath], '**/*').length > 0; } private handleEvent(filepath: string) { diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index de2a2fb6538e..b793282fcf2a 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -216,7 +216,7 @@ const formatPaths = ( if ( (config.testMatch && config.testMatch.length && - micromatch([filePath], config.testMatch).length) || + micromatch([filePath], config.testMatch).length > 0) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); diff --git a/packages/jest-transform/src/shouldInstrument.ts b/packages/jest-transform/src/shouldInstrument.ts index 90cef21dd0c6..aa3de070701c 100644 --- a/packages/jest-transform/src/shouldInstrument.ts +++ b/packages/jest-transform/src/shouldInstrument.ts @@ -59,10 +59,10 @@ export default function shouldInstrument( // still cover if `only` is specified !options.collectCoverageOnlyFrom && options.collectCoverageFrom && - !micromatch( + micromatch( [replacePathSepForGlob(path.relative(config.rootDir, filename))], options.collectCoverageFrom, - ).length + ).length === 0 ) { return false; }