From 44054afb917dd2a02f01adfc292375d5752d77f2 Mon Sep 17 00:00:00 2001 From: Dmitry Molotkov Date: Sat, 19 Jan 2019 02:54:51 +0300 Subject: [PATCH] chore: upgrade to micromatch 3 (#6650) --- CHANGELOG.md | 1 + e2e/runJest.js | 2 +- package.json | 3 +- packages/jest-cli/package.json | 2 +- packages/jest-cli/src/SearchSource.js | 4 ++- .../src/__tests__/SearchSource.test.js | 34 +++++++++---------- .../src/__tests__/runJestWithCoverage.test.js | 8 ++++- packages/jest-cli/src/runJest.js | 10 +++--- packages/jest-config/package.json | 2 +- packages/jest-config/src/normalize.js | 26 +++++++++----- packages/jest-haste-map/package.json | 3 +- packages/jest-haste-map/src/HasteFS.js | 3 +- packages/jest-message-util/package.json | 2 +- packages/jest-message-util/src/index.js | 2 +- packages/jest-runtime/package.json | 2 +- .../src/__tests__/should_instrument.test.js | 16 --------- packages/jest-runtime/src/shouldInstrument.js | 9 ++--- packages/jest-util/src/index.js | 2 ++ .../jest-util/src/replacePathSepForGlob.js | 14 ++++++++ scripts/browserBuild.js | 2 -- yarn.lock | 27 +++------------ 21 files changed, 88 insertions(+), 86 deletions(-) create mode 100644 packages/jest-util/src/replacePathSepForGlob.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 07746d020b08..3842cf0ae463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ - `[*]` [**BREAKING**] Require Node.js 6+ for all packages ([#7258](https://github.com/facebook/jest/pull/7258)) - `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285)) +- `[*]` [**BREAKING**] Upgrade to Micromatch 3 ([#6650](https://github.com/facebook/jest/pull/6650)) - `[docs]` Fix message property in custom matcher example to return a function instead of a constant. ([#7426](https://github.com/facebook/jest/pull/7426)) - `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301)) - `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150)) diff --git a/e2e/runJest.js b/e2e/runJest.js index 3c49bfc8b383..d1765d1b140d 100644 --- a/e2e/runJest.js +++ b/e2e/runJest.js @@ -12,7 +12,7 @@ import path from 'path'; import fs from 'fs'; import execa, {sync as spawnSync} from 'execa'; import {Writable} from 'readable-stream'; -const stripAnsi = require('strip-ansi'); +import stripAnsi from 'strip-ansi'; import {normalizeIcons} from './Utils'; const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js'); diff --git a/package.json b/package.json index fb99a422887b..9992744ba9bf 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "karma-mocha": "^1.3.0", "left-pad": "^1.1.1", "lerna": "3.10.5", - "micromatch": "^2.3.11", + "micromatch": "^3.1.10", "mkdirp": "^0.5.1", "mocha": "^5.0.1", "mock-fs": "^4.4.1", @@ -60,7 +60,6 @@ "rollup-plugin-flow": "^1.1.1", "rollup-plugin-json": "^3.1.0", "rollup-plugin-node-builtins": "^2.1.1", - "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-node-resolve": "^4.0.0", "slash": "^2.0.0", "string-length": "^2.0.0", diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index de4c76d0e097..c84b1f30021a 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -30,7 +30,7 @@ "jest-validate": "^23.6.0", "jest-watcher": "^23.4.0", "jest-worker": "^23.2.0", - "micromatch": "^2.3.11", + "micromatch": "^3.1.10", "node-notifier": "^5.2.1", "p-each-series": "^1.0.0", "pirates": "^4.0.0", diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 1744ef00bb2a..3d004d8ef140 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -19,6 +19,7 @@ import testPathPatternToRegExp from './testPathPatternToRegexp'; import {escapePathForRegex} from 'jest-regex-util'; import {replaceRootDirInPath} from 'jest-config'; import {buildSnapshotResolver} from 'jest-snapshot'; +import {replacePathSepForGlob} from 'jest-util'; type SearchResult = {| noSCM?: boolean, @@ -48,7 +49,8 @@ const globsToMatcher = (globs: ?Array) => { return () => true; } - return path => micromatch([path], globs, {dot: true}).length > 0; + return path => + micromatch.some(replacePathSepForGlob(path), globs, {dot: true}); }; const regexToMatcher = (testRegex: Array) => { diff --git a/packages/jest-cli/src/__tests__/SearchSource.test.js b/packages/jest-cli/src/__tests__/SearchSource.test.js index 53d979ec0d56..0a5ddef370dc 100644 --- a/packages/jest-cli/src/__tests__/SearchSource.test.js +++ b/packages/jest-cli/src/__tests__/SearchSource.test.js @@ -9,9 +9,9 @@ 'use strict'; import path from 'path'; -import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; jest.setTimeout(15000); + const rootDir = path.resolve(__dirname, 'test_root'); const testRegex = path.sep + '__testtests__' + path.sep; const testMatch = ['**/__testtests__/**/*']; @@ -23,8 +23,6 @@ let findMatchingTests; let normalize; describe('SearchSource', () => { - skipSuiteOnWindows(); - const name = 'SearchSource'; let Runtime; let SearchSource; @@ -481,22 +479,24 @@ describe('SearchSource', () => { }); it('does not mistake roots folders with prefix names', async () => { - const config = normalize( - { - name, - rootDir: '.', - roots: ['/foo/bar/prefix'], - }, - {}, - ).options; + if (process.platform !== 'win32') { + const config = normalize( + { + name, + rootDir: '.', + roots: ['/foo/bar/prefix'], + }, + {}, + ).options; - searchSource = new SearchSource( - await Runtime.createContext(config, {maxWorkers}), - ); + searchSource = new SearchSource( + await Runtime.createContext(config, {maxWorkers}), + ); - const input = ['/foo/bar/prefix-suffix/__tests__/my-test.test.js']; - const data = searchSource.findTestsByPaths(input); - expect(data.tests).toEqual([]); + const input = ['/foo/bar/prefix-suffix/__tests__/my-test.test.js']; + const data = searchSource.findTestsByPaths(input); + expect(data.tests).toEqual([]); + } }); }); }); diff --git a/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js b/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js index 21a9d76c0c40..e0ceb5266755 100644 --- a/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js +++ b/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js @@ -2,7 +2,13 @@ import runJest from '../runJest'; -jest.mock('jest-util'); +jest.mock('jest-util', () => { + const util = jest.requireActual('jest-util'); + return { + ...jest.genMockFromModule('jest-util'), + replacePathSepForGlob: util.replacePathSepForGlob, + }; +}); jest.mock( '../TestScheduler', diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index 8e3a6dcb1785..121cb201c72e 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -19,7 +19,7 @@ import micromatch from 'micromatch'; import chalk from 'chalk'; import path from 'path'; import {sync as realpath} from 'realpath-native'; -import {Console, formatTestResults} from 'jest-util'; +import {Console, formatTestResults, replacePathSepForGlob} from 'jest-util'; import exit from 'exit'; import fs from 'graceful-fs'; import getNoTestsFoundMessage from './getNoTestsFoundMessage'; @@ -165,10 +165,12 @@ export default (async function runJest({ matches.collectCoverageFrom.filter(filename => { if ( globalConfig.collectCoverageFrom && - !micromatch( - [path.relative(globalConfig.rootDir, filename)], + !micromatch.some( + replacePathSepForGlob( + path.relative(globalConfig.rootDir, filename), + ), globalConfig.collectCoverageFrom, - ).length + ) ) { return false; } diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index eb9aeb85a2ab..f41992144802 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -21,7 +21,7 @@ "jest-resolve": "^23.6.0", "jest-util": "^23.4.0", "jest-validate": "^23.6.0", - "micromatch": "^2.3.11", + "micromatch": "^3.1.10", "pretty-format": "^23.6.0", "realpath-native": "^1.0.2" }, diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 7c08a098c013..2eb122c48bda 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -21,7 +21,7 @@ import glob from 'glob'; import path from 'path'; import {ValidationError, validate} from 'jest-validate'; import validatePattern from './validatePattern'; -import {clearLine} from 'jest-util'; +import {clearLine, replacePathSepForGlob} from 'jest-util'; import chalk from 'chalk'; import getMaxWorkers from './getMaxWorkers'; import micromatch from 'micromatch'; @@ -609,10 +609,20 @@ export default function normalize(options: InitialOptions, argv: Argv) { break; case 'moduleDirectories': case 'testMatch': - value = _replaceRootDirTags( - escapeGlobCharacters(options.rootDir), - options[key], - ); + { + const replacedRootDirTags = _replaceRootDirTags( + escapeGlobCharacters(options.rootDir), + options[key], + ); + + if (replacedRootDirTags) { + value = Array.isArray(replacedRootDirTags) + ? replacedRootDirTags.map(replacePathSepForGlob) + : replacePathSepForGlob(replacedRootDirTags); + } else { + value = replacedRootDirTags; + } + } break; case 'testRegex': value = options[key] @@ -822,10 +832,10 @@ export default function normalize(options: InitialOptions, argv: Argv) { if (newOptions.collectCoverageFrom) { collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => { if ( - !micromatch( - [path.relative(options.rootDir, filename)], + !micromatch.some( + replacePathSepForGlob(path.relative(options.rootDir, filename)), newOptions.collectCoverageFrom, - ).length + ) ) { return patterns; } diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index 95aaa8d0544a..c3ef408ebf02 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -13,8 +13,9 @@ "graceful-fs": "^4.1.15", "invariant": "^2.2.4", "jest-serializer": "^23.0.1", + "jest-util": "^23.4.0", "jest-worker": "^23.2.0", - "micromatch": "^2.3.11", + "micromatch": "^3.1.10", "sane": "^3.0.0" }, "engines": { diff --git a/packages/jest-haste-map/src/HasteFS.js b/packages/jest-haste-map/src/HasteFS.js index 617ef744850e..c703376accde 100644 --- a/packages/jest-haste-map/src/HasteFS.js +++ b/packages/jest-haste-map/src/HasteFS.js @@ -10,6 +10,7 @@ import type {Glob, Path} from 'types/Config'; import type {FileData} from 'types/HasteMap'; +import {replacePathSepForGlob} from 'jest-util'; import * as fastPath from './lib/fast_path'; import micromatch from 'micromatch'; import H from './constants'; @@ -78,7 +79,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([filePath], globs).length) { + if (micromatch.some(replacePathSepForGlob(filePath), globs)) { files.add(file); } } diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index 72a1c4116161..fcf8b4858fc1 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -14,7 +14,7 @@ "dependencies": { "@babel/code-frame": "^7.0.0", "chalk": "^2.0.1", - "micromatch": "^2.3.11", + "micromatch": "^3.1.10", "slash": "^2.0.0", "stack-utils": "^1.0.1" } diff --git a/packages/jest-message-util/src/index.js b/packages/jest-message-util/src/index.js index 87c95800454a..48afb9ec2a31 100644 --- a/packages/jest-message-util/src/index.js +++ b/packages/jest-message-util/src/index.js @@ -210,7 +210,7 @@ const formatPaths = (config: StackTraceConfig, relativeTestPath, line) => { if ( (config.testMatch && config.testMatch.length && - micromatch(filePath, config.testMatch)) || + micromatch.some(filePath, config.testMatch)) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); diff --git a/packages/jest-runtime/package.json b/packages/jest-runtime/package.json index 41f4c6c2978c..5e74ff84ef95 100644 --- a/packages/jest-runtime/package.json +++ b/packages/jest-runtime/package.json @@ -25,7 +25,7 @@ "jest-snapshot": "^23.6.0", "jest-util": "^23.4.0", "jest-validate": "^23.6.0", - "micromatch": "^2.3.11", + "micromatch": "^3.1.10", "realpath-native": "^1.0.0", "slash": "^2.0.0", "strip-bom": "3.0.0", diff --git a/packages/jest-runtime/src/__tests__/should_instrument.test.js b/packages/jest-runtime/src/__tests__/should_instrument.test.js index 3601007aec57..376e8e7d0b4f 100644 --- a/packages/jest-runtime/src/__tests__/should_instrument.test.js +++ b/packages/jest-runtime/src/__tests__/should_instrument.test.js @@ -93,22 +93,6 @@ describe('shouldInstrument', () => { ); }); - it('should should match invalid globs, to be removed in the next major', () => { - const testSingleCollectCoverageFrom = pattern => - testShouldInstrument( - 'do/collect/coverage.js', - { - collectCoverage: true, - collectCoverageFrom: [pattern], - }, - defaultConfig, - ); - - testSingleCollectCoverageFrom('**/do/**/*.{js}'); - testSingleCollectCoverageFrom('**/do/**/*.{js|ts}'); - testSingleCollectCoverageFrom('**/do/**.js'); - }); - it('should return true if the file is not in coveragePathIgnorePatterns', () => { testShouldInstrument('do/collect/coverage.js', defaultOptions, { coveragePathIgnorePatterns: ['dont'], diff --git a/packages/jest-runtime/src/shouldInstrument.js b/packages/jest-runtime/src/shouldInstrument.js index 769105a30e86..6717fbea3e52 100644 --- a/packages/jest-runtime/src/shouldInstrument.js +++ b/packages/jest-runtime/src/shouldInstrument.js @@ -12,6 +12,7 @@ import type {Options} from './ScriptTransformer'; import path from 'path'; import {escapePathForRegex} from 'jest-regex-util'; +import {replacePathSepForGlob} from 'jest-util'; import micromatch from 'micromatch'; const MOCKS_PATTERN = new RegExp( @@ -49,7 +50,7 @@ export default function shouldInstrument( if ( config.testMatch && config.testMatch.length && - micromatch([filename], config.testMatch).length + micromatch.some(replacePathSepForGlob(filename), config.testMatch) ) { return false; } @@ -68,10 +69,10 @@ export default function shouldInstrument( // still cover if `only` is specified !options.collectCoverageOnlyFrom && options.collectCoverageFrom && - !micromatch( - [path.relative(config.rootDir, filename)], + !micromatch.some( + replacePathSepForGlob(path.relative(config.rootDir, filename)), options.collectCoverageFrom, - ).length + ) ) { return false; } diff --git a/packages/jest-util/src/index.js b/packages/jest-util/src/index.js index 7c978c666010..04aed91a67bb 100644 --- a/packages/jest-util/src/index.js +++ b/packages/jest-util/src/index.js @@ -24,6 +24,7 @@ import setGlobal from './setGlobal'; import deepCyclicCopy from './deepCyclicCopy'; import convertDescriptorToString from './convertDescriptorToString'; import * as specialChars from './specialChars'; +import replacePathSepForGlob from './replacePathSepForGlob'; module.exports = { BufferedConsole, @@ -41,6 +42,7 @@ module.exports = { getFailedSnapshotTests, installCommonGlobals, isInteractive, + replacePathSepForGlob, setGlobal, specialChars, }; diff --git a/packages/jest-util/src/replacePathSepForGlob.js b/packages/jest-util/src/replacePathSepForGlob.js new file mode 100644 index 000000000000..1c4362b02d81 --- /dev/null +++ b/packages/jest-util/src/replacePathSepForGlob.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type {Path, Glob} from 'types/Config'; + +export default function replacePathSepForGlob(path: Path): Glob { + return path.replace(/\\(?![{}()+?.^$])/g, '/'); +} diff --git a/scripts/browserBuild.js b/scripts/browserBuild.js index 045135e33b7a..f9f02827cd74 100644 --- a/scripts/browserBuild.js +++ b/scripts/browserBuild.js @@ -11,7 +11,6 @@ const rollup = require('rollup').rollup; const rollupResolve = require('rollup-plugin-node-resolve'); const rollupCommonjs = require('rollup-plugin-commonjs'); const rollupBuiltins = require('rollup-plugin-node-builtins'); -const rollupGlobals = require('rollup-plugin-node-globals'); const rollupJson = require('rollup-plugin-json'); const rollupBabel = require('rollup-plugin-babel'); const rollupFlow = require('rollup-plugin-flow'); @@ -52,7 +51,6 @@ function browserBuild(pkgName, entryPath, destination) { rollupJson(), rollupCommonjs(), rollupBabel(babelEs5Options), - rollupGlobals(), rollupBuiltins(), rollupResolve(), ], diff --git a/yarn.lock b/yarn.lock index ee6616cdedca..fa6719676794 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1544,7 +1544,7 @@ acorn-walk@^6.0.1, acorn-walk@^6.1.0: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.1.1.tgz#d363b66f5fac5f018ff9c3a1e7b6f8e310cc3913" integrity sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw== -acorn@^5.5.3, acorn@^5.7.3: +acorn@^5.5.3: version "5.7.3" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== @@ -2578,7 +2578,7 @@ buffer-crc32@~0.2.3: resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" integrity sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI= -buffer-es6@^4.9.2, buffer-es6@^4.9.3: +buffer-es6@^4.9.2: version "4.9.3" resolved "https://registry.yarnpkg.com/buffer-es6/-/buffer-es6-4.9.3.tgz#f26347b82df76fd37e18bcb5288c4970cfd5c404" integrity sha1-8mNHuC33b9N+GLy1KIxJcM/VxAQ= @@ -8231,13 +8231,6 @@ ltgt@^2.1.2: resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5" integrity sha1-81ypHEk/e3PaDgdJUwTxezH4fuU= -magic-string@^0.22.5: - version "0.22.5" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.5.tgz#8e9cf5afddf44385c1da5bc2a6a0dbd10b03657e" - integrity sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w== - dependencies: - vlq "^0.2.2" - magic-string@^0.25.1: version "0.25.1" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.1.tgz#b1c248b399cd7485da0fe7385c2fc7011843266e" @@ -10312,7 +10305,7 @@ private@^0.1.6: resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" integrity sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg== -process-es6@^0.11.2, process-es6@^0.11.6: +process-es6@^0.11.2: version "0.11.6" resolved "https://registry.yarnpkg.com/process-es6/-/process-es6-0.11.6.tgz#c6bb389f9a951f82bd4eb169600105bd2ff9c778" integrity sha1-xrs4n5qVH4K9TrFpYAEFvS/5x3g= @@ -11346,18 +11339,6 @@ rollup-plugin-node-builtins@^2.1.1: crypto-browserify "^3.11.0" process-es6 "^0.11.2" -rollup-plugin-node-globals@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-node-globals/-/rollup-plugin-node-globals-1.4.0.tgz#5e1f24a9bb97c0ef51249f625e16c7e61b7c020b" - integrity sha512-xRkB+W/m1KLIzPUmG0ofvR+CPNcvuCuNdjVBVS7ALKSxr3EDhnzNceGkGi1m8MToSli13AzKFYH4ie9w3I5L3g== - dependencies: - acorn "^5.7.3" - buffer-es6 "^4.9.3" - estree-walker "^0.5.2" - magic-string "^0.22.5" - process-es6 "^0.11.6" - rollup-pluginutils "^2.3.1" - rollup-plugin-node-resolve@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.0.0.tgz#9bc6b8205e9936cc0e26bba2415f1ecf1e64d9b2" @@ -13213,7 +13194,7 @@ vinyl@^1.0.0: clone-stats "^0.0.1" replace-ext "0.0.1" -vlq@^0.2.1, vlq@^0.2.2: +vlq@^0.2.1: version "0.2.3" resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" integrity sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==