diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cde16edb0bd..e7cb0197dfaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,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-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 07cee81379e9..634e506faf11 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 = require('micromatch'); import {sync as realpath} from 'realpath-native'; import Resolver = require('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 === 0 ) { return patterns; } 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-core/src/SearchSource.ts b/packages/jest-core/src/SearchSource.ts index 701a29f07b4b..e974ce42ab84 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 = require('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 > 0; const regexToMatcher = (testRegex: Array) => (path: Config.Path) => testRegex.some(testRegex => new RegExp(testRegex).test(path)); 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-haste-map/src/HasteFS.ts b/packages/jest-haste-map/src/HasteFS.ts index 1f92658b3ddf..efe02081659d 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 = require('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 > 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 bb8563ce6c26..dd71d1df4908 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -9,8 +9,8 @@ import * as fs from 'fs'; import * as path from 'path'; import {EventEmitter} from 'events'; -import anymatch = require('anymatch'); -import {some as micromatchSome} from 'micromatch'; +import anymatch, {Matcher} from 'anymatch'; +import micromatch = require('micromatch'); // eslint-disable-next-line import {Watcher} from 'fsevents'; // @ts-ignore no types @@ -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; }, @@ -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 > 0 + : this.dot || micromatch([relativePath], '**/*').length > 0; } private handleEvent(filepath: string) { 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-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index cd95635ae23b..bf8bb1260734 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 = require('micromatch'); import slash = require('slash'); import {codeFrameColumns} from '@babel/code-frame'; import StackUtils = require('stack-utils'); @@ -216,7 +216,7 @@ const formatPaths = ( if ( (config.testMatch && config.testMatch.length && - micromatchSome(filePath, config.testMatch)) || + micromatch([filePath], config.testMatch).length > 0) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); 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/packages/jest-transform/src/shouldInstrument.ts b/packages/jest-transform/src/shouldInstrument.ts index bf38e514e84c..3c5c8a89508a 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 = require('micromatch'); import {ShouldInstrumentOptions} from './types'; const MOCKS_PATTERN = new RegExp( @@ -27,7 +27,7 @@ export default function shouldInstrument( if ( config.forceCoverageMatch.length && - micromatchAny(filename, config.forceCoverageMatch) + micromatch.any(filename, config.forceCoverageMatch) ) { return true; } @@ -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 === 0 ) { return false; } 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==