Skip to content

Commit db46191

Browse files
aldarundcaptain-yossarian
authored andcommitted
chore: upgrade to micromatch 3 (jestjs#6650)
1 parent 34197ab commit db46191

File tree

21 files changed

+88
-86
lines changed

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
}

0 commit comments

Comments
 (0)