Skip to content

Commit 58e17b3

Browse files
committed
use match instead of some
1 parent a3379f5 commit 58e17b3

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

packages/jest-config/src/normalize.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Config} from '@jest/types';
1212
import {ValidationError, validate} from 'jest-validate';
1313
import {clearLine, replacePathSepForGlob} from 'jest-util';
1414
import chalk from 'chalk';
15-
import {some as micromatchSome} from 'micromatch';
15+
import micromatch from 'micromatch';
1616
import {sync as realpath} from 'realpath-native';
1717
import Resolver from 'jest-resolve';
1818
import {replacePathSepForRegex} from 'jest-regex-util';
@@ -982,10 +982,10 @@ export default function normalize(
982982
if (newOptions.collectCoverageFrom) {
983983
collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => {
984984
if (
985-
!micromatchSome(
986-
replacePathSepForGlob(path.relative(options.rootDir, filename)),
985+
!micromatch(
986+
[replacePathSepForGlob(path.relative(options.rootDir, filename))],
987987
newOptions.collectCoverageFrom!,
988-
)
988+
).length
989989
) {
990990
return patterns;
991991
}

packages/jest-core/src/SearchSource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as path from 'path';
9-
import {some as micromatchSome} from 'micromatch';
9+
import micromatch from 'micromatch';
1010
import {Context} from 'jest-runtime';
1111
import {Config} from '@jest/types';
1212
import {Test} from 'jest-runner';
@@ -37,7 +37,7 @@ export type TestSelectionConfig = {
3737
};
3838

3939
const globsToMatcher = (globs: Array<Config.Glob>) => (path: Config.Path) =>
40-
micromatchSome(replacePathSepForGlob(path), globs, {dot: true});
40+
!!micromatch([replacePathSepForGlob(path)], globs, {dot: true}).length;
4141

4242
const regexToMatcher = (testRegex: Array<string>) => (path: Config.Path) =>
4343
testRegex.some(testRegex => new RegExp(testRegex).test(path));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {some as micromatchSome} from 'micromatch';
8+
import micromatch from 'micromatch';
99
import {replacePathSepForGlob} from 'jest-util';
1010
import {Config} from '@jest/types';
1111
import {FileData} from './types';
@@ -86,7 +86,7 @@ export default class HasteFS {
8686
const files = new Set<string>();
8787
for (const file of this.getAbsoluteFileIterator()) {
8888
const filePath = root ? fastPath.relative(root, file) : file;
89-
if (micromatchSome(replacePathSepForGlob(filePath), globs)) {
89+
if (micromatch([replacePathSepForGlob(filePath)], globs).length) {
9090
files.add(file);
9191
}
9292
}

packages/jest-haste-map/src/lib/FSEventsWatcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as fs from 'fs';
1010
import * as path from 'path';
1111
import {EventEmitter} from 'events';
1212
import anymatch, {Matcher} from 'anymatch';
13-
import {some as micromatchSome} from 'micromatch';
13+
import micromatch from 'micromatch';
1414
// eslint-disable-next-line
1515
import {Watcher} from 'fsevents';
1616
// @ts-ignore no types
@@ -139,8 +139,8 @@ class FSEventsWatcher extends EventEmitter {
139139
return false;
140140
}
141141
return this.glob.length
142-
? micromatchSome(relativePath, this.glob, {dot: this.dot})
143-
: this.dot || micromatchSome(relativePath, '**/*');
142+
? !!micromatch([relativePath], this.glob, {dot: this.dot}).length
143+
: !!this.dot || micromatch([relativePath], '**/*').length;
144144
}
145145

146146
private handleEvent(filepath: string) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path';
1010
import {Config} from '@jest/types';
1111
import {AssertionResult, SerializableError} from '@jest/test-result';
1212
import chalk from 'chalk';
13-
import {some as micromatchSome} from 'micromatch';
13+
import micromatch from 'micromatch';
1414
import slash from 'slash';
1515
import {codeFrameColumns} from '@babel/code-frame';
1616
import StackUtils from 'stack-utils';
@@ -216,7 +216,7 @@ const formatPaths = (
216216
if (
217217
(config.testMatch &&
218218
config.testMatch.length &&
219-
micromatchSome(filePath, config.testMatch)) ||
219+
micromatch([filePath], config.testMatch).length) ||
220220
filePath === relativeTestPath
221221
) {
222222
filePath = chalk.reset.cyan(filePath);

packages/jest-transform/src/shouldInstrument.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99
import {Config} from '@jest/types';
1010
import {escapePathForRegex} from 'jest-regex-util';
1111
import {replacePathSepForGlob} from 'jest-util';
12-
import {any as micromatchAny, some as micromatchSome} from 'micromatch';
12+
import micromatch, {any as micromatchAny} from 'micromatch';
1313
import {ShouldInstrumentOptions} from './types';
1414

1515
const MOCKS_PATTERN = new RegExp(
@@ -39,7 +39,9 @@ export default function shouldInstrument(
3939
return false;
4040
}
4141

42-
if (micromatchSome(replacePathSepForGlob(filename), config.testMatch)) {
42+
if (
43+
micromatch([replacePathSepForGlob(filename)], config.testMatch).length
44+
) {
4345
return false;
4446
}
4547
}
@@ -57,10 +59,10 @@ export default function shouldInstrument(
5759
// still cover if `only` is specified
5860
!options.collectCoverageOnlyFrom &&
5961
options.collectCoverageFrom &&
60-
!micromatchSome(
61-
replacePathSepForGlob(path.relative(config.rootDir, filename)),
62+
!micromatch(
63+
[replacePathSepForGlob(path.relative(config.rootDir, filename))],
6264
options.collectCoverageFrom,
63-
)
65+
).length
6466
) {
6567
return false;
6668
}

0 commit comments

Comments
 (0)