Skip to content

Commit

Permalink
use match instead of some
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee committed Aug 19, 2019
1 parent 70a3cd0 commit 9e9b529
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Config} from '@jest/types';
import {ValidationError, validate} from 'jest-validate';
import {clearLine, replacePathSepForGlob} from 'jest-util';
import chalk from 'chalk';
import {some as micromatchSome} from 'micromatch';
import micromatch from 'micromatch';
import {sync as realpath} from 'realpath-native';
import Resolver from 'jest-resolve';
import {replacePathSepForRegex} from 'jest-regex-util';
Expand Down Expand Up @@ -982,10 +982,10 @@ export default function normalize(
if (newOptions.collectCoverageFrom) {
collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => {
if (
!micromatchSome(
replacePathSepForGlob(path.relative(options.rootDir, filename)),
!micromatch(
[replacePathSepForGlob(path.relative(options.rootDir, filename))],
newOptions.collectCoverageFrom!,
)
).length
) {
return patterns;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import {some as micromatchSome} from 'micromatch';
import micromatch from 'micromatch';
import {Context} from 'jest-runtime';
import {Config} from '@jest/types';
import {Test} from 'jest-runner';
Expand Down Expand Up @@ -37,7 +37,7 @@ export type TestSelectionConfig = {
};

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

const regexToMatcher = (testRegex: Array<string>) => (path: Config.Path) =>
testRegex.some(testRegex => new RegExp(testRegex).test(path));
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/HasteFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {some as micromatchSome} from 'micromatch';
import micromatch from 'micromatch';
import {replacePathSepForGlob} from 'jest-util';
import {Config} from '@jest/types';
import {FileData} from './types';
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class HasteFS {
const files = new Set<string>();
for (const file of this.getAbsoluteFileIterator()) {
const filePath = root ? fastPath.relative(root, file) : file;
if (micromatchSome(replacePathSepForGlob(filePath), globs)) {
if (micromatch([replacePathSepForGlob(filePath)], globs).length) {
files.add(file);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-haste-map/src/lib/FSEventsWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as fs from 'fs';
import * as path from 'path';
import {EventEmitter} from 'events';
import anymatch, {Matcher} from 'anymatch';
import {some as micromatchSome} from 'micromatch';
import micromatch from 'micromatch';
// eslint-disable-next-line
import {Watcher} from 'fsevents';
// @ts-ignore no types
Expand Down Expand Up @@ -139,8 +139,8 @@ class FSEventsWatcher extends EventEmitter {
return false;
}
return this.glob.length
? micromatchSome(relativePath, this.glob, {dot: this.dot})
: this.dot || micromatchSome(relativePath, '**/*');
? !!micromatch([relativePath], this.glob, {dot: this.dot}).length
: !!this.dot || micromatch([relativePath], '**/*').length;
}

private handleEvent(filepath: string) {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import {Config} from '@jest/types';
import {AssertionResult, SerializableError} from '@jest/test-result';
import chalk from 'chalk';
import {some as micromatchSome} from 'micromatch';
import micromatch from 'micromatch';
import slash from 'slash';
import {codeFrameColumns} from '@babel/code-frame';
import StackUtils from 'stack-utils';
Expand Down Expand Up @@ -216,7 +216,7 @@ const formatPaths = (
if (
(config.testMatch &&
config.testMatch.length &&
micromatchSome(filePath, config.testMatch)) ||
micromatch([filePath], config.testMatch).length) ||
filePath === relativeTestPath
) {
filePath = chalk.reset.cyan(filePath);
Expand Down
12 changes: 7 additions & 5 deletions packages/jest-transform/src/shouldInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import {Config} from '@jest/types';
import {escapePathForRegex} from 'jest-regex-util';
import {replacePathSepForGlob} from 'jest-util';
import {any as micromatchAny, some as micromatchSome} from 'micromatch';
import micromatch, {any as micromatchAny} from 'micromatch';
import {ShouldInstrumentOptions} from './types';

const MOCKS_PATTERN = new RegExp(
Expand Down Expand Up @@ -39,7 +39,9 @@ export default function shouldInstrument(
return false;
}

if (micromatchSome(replacePathSepForGlob(filename), config.testMatch)) {
if (
micromatch([replacePathSepForGlob(filename)], config.testMatch).length
) {
return false;
}
}
Expand All @@ -57,10 +59,10 @@ export default function shouldInstrument(
// still cover if `only` is specified
!options.collectCoverageOnlyFrom &&
options.collectCoverageFrom &&
!micromatchSome(
replacePathSepForGlob(path.relative(config.rootDir, filename)),
!micromatch(
[replacePathSepForGlob(path.relative(config.rootDir, filename))],
options.collectCoverageFrom,
)
).length
) {
return false;
}
Expand Down

0 comments on commit 9e9b529

Please sign in to comment.