Skip to content

Commit

Permalink
chore: upgrade to micromatch 3 (#6650)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldarund authored and SimenB committed Jan 18, 2019
1 parent 5442d34 commit 44054af
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 86 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion e2e/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,7 +49,8 @@ const globsToMatcher = (globs: ?Array<Glob>) => {
return () => true;
}

return path => micromatch([path], globs, {dot: true}).length > 0;
return path =>
micromatch.some(replacePathSepForGlob(path), globs, {dot: true});
};

const regexToMatcher = (testRegex: Array<string>) => {
Expand Down
34 changes: 17 additions & 17 deletions packages/jest-cli/src/__tests__/SearchSource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__/**/*'];
Expand All @@ -23,8 +23,6 @@ let findMatchingTests;
let normalize;

describe('SearchSource', () => {
skipSuiteOnWindows();

const name = 'SearchSource';
let Runtime;
let SearchSource;
Expand Down Expand Up @@ -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([]);
}
});
});
});
8 changes: 7 additions & 1 deletion packages/jest-cli/src/__tests__/runJestWithCoverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
26 changes: 18 additions & 8 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-haste-map/src/HasteFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-message-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-message-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 0 additions & 16 deletions packages/jest-runtime/src/__tests__/should_instrument.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-runtime/src/shouldInstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,6 +42,7 @@ module.exports = {
getFailedSnapshotTests,
installCommonGlobals,
isInteractive,
replacePathSepForGlob,
setGlobal,
specialChars,
};
14 changes: 14 additions & 0 deletions packages/jest-util/src/replacePathSepForGlob.js
Original file line number Diff line number Diff line change
@@ -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, '/');
}
2 changes: 0 additions & 2 deletions scripts/browserBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -52,7 +51,6 @@ function browserBuild(pkgName, entryPath, destination) {
rollupJson(),
rollupCommonjs(),
rollupBabel(babelEs5Options),
rollupGlobals(),
rollupBuiltins(),
rollupResolve(),
],
Expand Down
Loading

0 comments on commit 44054af

Please sign in to comment.