Skip to content

Commit 44054af

Browse files
aldarundSimenB
authored andcommitted
chore: upgrade to micromatch 3 (#6650)
1 parent 5442d34 commit 44054af

21 files changed

+88
-86
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121

122122
- `[*]` [**BREAKING**] Require Node.js 6+ for all packages ([#7258](https://github.com/facebook/jest/pull/7258))
123123
- `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
124+
- `[*]` [**BREAKING**] Upgrade to Micromatch 3 ([#6650](https://github.com/facebook/jest/pull/6650))
124125
- `[docs]` Fix message property in custom matcher example to return a function instead of a constant. ([#7426](https://github.com/facebook/jest/pull/7426))
125126
- `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301))
126127
- `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150))

e2e/runJest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import path from 'path';
1212
import fs from 'fs';
1313
import execa, {sync as spawnSync} from 'execa';
1414
import {Writable} from 'readable-stream';
15-
const stripAnsi = require('strip-ansi');
15+
import stripAnsi from 'strip-ansi';
1616
import {normalizeIcons} from './Utils';
1717

1818
const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js');

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"karma-mocha": "^1.3.0",
4343
"left-pad": "^1.1.1",
4444
"lerna": "3.10.5",
45-
"micromatch": "^2.3.11",
45+
"micromatch": "^3.1.10",
4646
"mkdirp": "^0.5.1",
4747
"mocha": "^5.0.1",
4848
"mock-fs": "^4.4.1",
@@ -60,7 +60,6 @@
6060
"rollup-plugin-flow": "^1.1.1",
6161
"rollup-plugin-json": "^3.1.0",
6262
"rollup-plugin-node-builtins": "^2.1.1",
63-
"rollup-plugin-node-globals": "^1.4.0",
6463
"rollup-plugin-node-resolve": "^4.0.0",
6564
"slash": "^2.0.0",
6665
"string-length": "^2.0.0",

packages/jest-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"jest-validate": "^23.6.0",
3131
"jest-watcher": "^23.4.0",
3232
"jest-worker": "^23.2.0",
33-
"micromatch": "^2.3.11",
33+
"micromatch": "^3.1.10",
3434
"node-notifier": "^5.2.1",
3535
"p-each-series": "^1.0.0",
3636
"pirates": "^4.0.0",

packages/jest-cli/src/SearchSource.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import testPathPatternToRegExp from './testPathPatternToRegexp';
1919
import {escapePathForRegex} from 'jest-regex-util';
2020
import {replaceRootDirInPath} from 'jest-config';
2121
import {buildSnapshotResolver} from 'jest-snapshot';
22+
import {replacePathSepForGlob} from 'jest-util';
2223

2324
type SearchResult = {|
2425
noSCM?: boolean,
@@ -48,7 +49,8 @@ const globsToMatcher = (globs: ?Array<Glob>) => {
4849
return () => true;
4950
}
5051

51-
return path => micromatch([path], globs, {dot: true}).length > 0;
52+
return path =>
53+
micromatch.some(replacePathSepForGlob(path), globs, {dot: true});
5254
};
5355

5456
const regexToMatcher = (testRegex: Array<string>) => {

packages/jest-cli/src/__tests__/SearchSource.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
'use strict';
1010

1111
import path from 'path';
12-
import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest';
1312

1413
jest.setTimeout(15000);
14+
1515
const rootDir = path.resolve(__dirname, 'test_root');
1616
const testRegex = path.sep + '__testtests__' + path.sep;
1717
const testMatch = ['**/__testtests__/**/*'];
@@ -23,8 +23,6 @@ let findMatchingTests;
2323
let normalize;
2424

2525
describe('SearchSource', () => {
26-
skipSuiteOnWindows();
27-
2826
const name = 'SearchSource';
2927
let Runtime;
3028
let SearchSource;
@@ -481,22 +479,24 @@ describe('SearchSource', () => {
481479
});
482480

483481
it('does not mistake roots folders with prefix names', async () => {
484-
const config = normalize(
485-
{
486-
name,
487-
rootDir: '.',
488-
roots: ['/foo/bar/prefix'],
489-
},
490-
{},
491-
).options;
482+
if (process.platform !== 'win32') {
483+
const config = normalize(
484+
{
485+
name,
486+
rootDir: '.',
487+
roots: ['/foo/bar/prefix'],
488+
},
489+
{},
490+
).options;
492491

493-
searchSource = new SearchSource(
494-
await Runtime.createContext(config, {maxWorkers}),
495-
);
492+
searchSource = new SearchSource(
493+
await Runtime.createContext(config, {maxWorkers}),
494+
);
496495

497-
const input = ['/foo/bar/prefix-suffix/__tests__/my-test.test.js'];
498-
const data = searchSource.findTestsByPaths(input);
499-
expect(data.tests).toEqual([]);
496+
const input = ['/foo/bar/prefix-suffix/__tests__/my-test.test.js'];
497+
const data = searchSource.findTestsByPaths(input);
498+
expect(data.tests).toEqual([]);
499+
}
500500
});
501501
});
502502
});

packages/jest-cli/src/__tests__/runJestWithCoverage.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import runJest from '../runJest';
44

5-
jest.mock('jest-util');
5+
jest.mock('jest-util', () => {
6+
const util = jest.requireActual('jest-util');
7+
return {
8+
...jest.genMockFromModule('jest-util'),
9+
replacePathSepForGlob: util.replacePathSepForGlob,
10+
};
11+
});
612

713
jest.mock(
814
'../TestScheduler',

packages/jest-cli/src/runJest.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import micromatch from 'micromatch';
1919
import chalk from 'chalk';
2020
import path from 'path';
2121
import {sync as realpath} from 'realpath-native';
22-
import {Console, formatTestResults} from 'jest-util';
22+
import {Console, formatTestResults, replacePathSepForGlob} from 'jest-util';
2323
import exit from 'exit';
2424
import fs from 'graceful-fs';
2525
import getNoTestsFoundMessage from './getNoTestsFoundMessage';
@@ -165,10 +165,12 @@ export default (async function runJest({
165165
matches.collectCoverageFrom.filter(filename => {
166166
if (
167167
globalConfig.collectCoverageFrom &&
168-
!micromatch(
169-
[path.relative(globalConfig.rootDir, filename)],
168+
!micromatch.some(
169+
replacePathSepForGlob(
170+
path.relative(globalConfig.rootDir, filename),
171+
),
170172
globalConfig.collectCoverageFrom,
171-
).length
173+
)
172174
) {
173175
return false;
174176
}

packages/jest-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"jest-resolve": "^23.6.0",
2222
"jest-util": "^23.4.0",
2323
"jest-validate": "^23.6.0",
24-
"micromatch": "^2.3.11",
24+
"micromatch": "^3.1.10",
2525
"pretty-format": "^23.6.0",
2626
"realpath-native": "^1.0.2"
2727
},

packages/jest-config/src/normalize.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import glob from 'glob';
2121
import path from 'path';
2222
import {ValidationError, validate} from 'jest-validate';
2323
import validatePattern from './validatePattern';
24-
import {clearLine} from 'jest-util';
24+
import {clearLine, replacePathSepForGlob} from 'jest-util';
2525
import chalk from 'chalk';
2626
import getMaxWorkers from './getMaxWorkers';
2727
import micromatch from 'micromatch';
@@ -609,10 +609,20 @@ export default function normalize(options: InitialOptions, argv: Argv) {
609609
break;
610610
case 'moduleDirectories':
611611
case 'testMatch':
612-
value = _replaceRootDirTags(
613-
escapeGlobCharacters(options.rootDir),
614-
options[key],
615-
);
612+
{
613+
const replacedRootDirTags = _replaceRootDirTags(
614+
escapeGlobCharacters(options.rootDir),
615+
options[key],
616+
);
617+
618+
if (replacedRootDirTags) {
619+
value = Array.isArray(replacedRootDirTags)
620+
? replacedRootDirTags.map(replacePathSepForGlob)
621+
: replacePathSepForGlob(replacedRootDirTags);
622+
} else {
623+
value = replacedRootDirTags;
624+
}
625+
}
616626
break;
617627
case 'testRegex':
618628
value = options[key]
@@ -822,10 +832,10 @@ export default function normalize(options: InitialOptions, argv: Argv) {
822832
if (newOptions.collectCoverageFrom) {
823833
collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => {
824834
if (
825-
!micromatch(
826-
[path.relative(options.rootDir, filename)],
835+
!micromatch.some(
836+
replacePathSepForGlob(path.relative(options.rootDir, filename)),
827837
newOptions.collectCoverageFrom,
828-
).length
838+
)
829839
) {
830840
return patterns;
831841
}

packages/jest-haste-map/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
"graceful-fs": "^4.1.15",
1414
"invariant": "^2.2.4",
1515
"jest-serializer": "^23.0.1",
16+
"jest-util": "^23.4.0",
1617
"jest-worker": "^23.2.0",
17-
"micromatch": "^2.3.11",
18+
"micromatch": "^3.1.10",
1819
"sane": "^3.0.0"
1920
},
2021
"engines": {

packages/jest-haste-map/src/HasteFS.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import type {Glob, Path} from 'types/Config';
1111
import type {FileData} from 'types/HasteMap';
1212

13+
import {replacePathSepForGlob} from 'jest-util';
1314
import * as fastPath from './lib/fast_path';
1415
import micromatch from 'micromatch';
1516
import H from './constants';
@@ -78,7 +79,7 @@ export default class HasteFS {
7879
const files = new Set();
7980
for (const file of this.getAbsoluteFileIterator()) {
8081
const filePath = root ? fastPath.relative(root, file) : file;
81-
if (micromatch([filePath], globs).length) {
82+
if (micromatch.some(replacePathSepForGlob(filePath), globs)) {
8283
files.add(file);
8384
}
8485
}

packages/jest-message-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"@babel/code-frame": "^7.0.0",
1616
"chalk": "^2.0.1",
17-
"micromatch": "^2.3.11",
17+
"micromatch": "^3.1.10",
1818
"slash": "^2.0.0",
1919
"stack-utils": "^1.0.1"
2020
}

packages/jest-message-util/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const formatPaths = (config: StackTraceConfig, relativeTestPath, line) => {
210210
if (
211211
(config.testMatch &&
212212
config.testMatch.length &&
213-
micromatch(filePath, config.testMatch)) ||
213+
micromatch.some(filePath, config.testMatch)) ||
214214
filePath === relativeTestPath
215215
) {
216216
filePath = chalk.reset.cyan(filePath);

packages/jest-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"jest-snapshot": "^23.6.0",
2626
"jest-util": "^23.4.0",
2727
"jest-validate": "^23.6.0",
28-
"micromatch": "^2.3.11",
28+
"micromatch": "^3.1.10",
2929
"realpath-native": "^1.0.0",
3030
"slash": "^2.0.0",
3131
"strip-bom": "3.0.0",

packages/jest-runtime/src/__tests__/should_instrument.test.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,6 @@ describe('shouldInstrument', () => {
9393
);
9494
});
9595

96-
it('should should match invalid globs, to be removed in the next major', () => {
97-
const testSingleCollectCoverageFrom = pattern =>
98-
testShouldInstrument(
99-
'do/collect/coverage.js',
100-
{
101-
collectCoverage: true,
102-
collectCoverageFrom: [pattern],
103-
},
104-
defaultConfig,
105-
);
106-
107-
testSingleCollectCoverageFrom('**/do/**/*.{js}');
108-
testSingleCollectCoverageFrom('**/do/**/*.{js|ts}');
109-
testSingleCollectCoverageFrom('**/do/**.js');
110-
});
111-
11296
it('should return true if the file is not in coveragePathIgnorePatterns', () => {
11397
testShouldInstrument('do/collect/coverage.js', defaultOptions, {
11498
coveragePathIgnorePatterns: ['dont'],

packages/jest-runtime/src/shouldInstrument.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {Options} from './ScriptTransformer';
1212

1313
import path from 'path';
1414
import {escapePathForRegex} from 'jest-regex-util';
15+
import {replacePathSepForGlob} from 'jest-util';
1516
import micromatch from 'micromatch';
1617

1718
const MOCKS_PATTERN = new RegExp(
@@ -49,7 +50,7 @@ export default function shouldInstrument(
4950
if (
5051
config.testMatch &&
5152
config.testMatch.length &&
52-
micromatch([filename], config.testMatch).length
53+
micromatch.some(replacePathSepForGlob(filename), config.testMatch)
5354
) {
5455
return false;
5556
}
@@ -68,10 +69,10 @@ export default function shouldInstrument(
6869
// still cover if `only` is specified
6970
!options.collectCoverageOnlyFrom &&
7071
options.collectCoverageFrom &&
71-
!micromatch(
72-
[path.relative(config.rootDir, filename)],
72+
!micromatch.some(
73+
replacePathSepForGlob(path.relative(config.rootDir, filename)),
7374
options.collectCoverageFrom,
74-
).length
75+
)
7576
) {
7677
return false;
7778
}

packages/jest-util/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import setGlobal from './setGlobal';
2424
import deepCyclicCopy from './deepCyclicCopy';
2525
import convertDescriptorToString from './convertDescriptorToString';
2626
import * as specialChars from './specialChars';
27+
import replacePathSepForGlob from './replacePathSepForGlob';
2728

2829
module.exports = {
2930
BufferedConsole,
@@ -41,6 +42,7 @@ module.exports = {
4142
getFailedSnapshotTests,
4243
installCommonGlobals,
4344
isInteractive,
45+
replacePathSepForGlob,
4446
setGlobal,
4547
specialChars,
4648
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import type {Path, Glob} from 'types/Config';
11+
12+
export default function replacePathSepForGlob(path: Path): Glob {
13+
return path.replace(/\\(?![{}()+?.^$])/g, '/');
14+
}

scripts/browserBuild.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const rollup = require('rollup').rollup;
1111
const rollupResolve = require('rollup-plugin-node-resolve');
1212
const rollupCommonjs = require('rollup-plugin-commonjs');
1313
const rollupBuiltins = require('rollup-plugin-node-builtins');
14-
const rollupGlobals = require('rollup-plugin-node-globals');
1514
const rollupJson = require('rollup-plugin-json');
1615
const rollupBabel = require('rollup-plugin-babel');
1716
const rollupFlow = require('rollup-plugin-flow');
@@ -52,7 +51,6 @@ function browserBuild(pkgName, entryPath, destination) {
5251
rollupJson(),
5352
rollupCommonjs(),
5453
rollupBabel(babelEs5Options),
55-
rollupGlobals(),
5654
rollupBuiltins(),
5755
rollupResolve(),
5856
],

0 commit comments

Comments
 (0)