From 58e17b3fc3477793aaa3a05cb18eefd0c454e855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 19 Aug 2019 20:43:15 +0200 Subject: [PATCH] use match instead of some --- packages/jest-config/src/normalize.ts | 8 ++++---- packages/jest-core/src/SearchSource.ts | 4 ++-- packages/jest-haste-map/src/HasteFS.ts | 4 ++-- packages/jest-haste-map/src/lib/FSEventsWatcher.ts | 6 +++--- packages/jest-message-util/src/index.ts | 4 ++-- packages/jest-transform/src/shouldInstrument.ts | 12 +++++++----- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index bc798f9bac3a..010dcbac1aba 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -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'; @@ -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; } diff --git a/packages/jest-core/src/SearchSource.ts b/packages/jest-core/src/SearchSource.ts index 4159137df91b..f1ef516300dc 100644 --- a/packages/jest-core/src/SearchSource.ts +++ b/packages/jest-core/src/SearchSource.ts @@ -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'; @@ -37,7 +37,7 @@ export type TestSelectionConfig = { }; const globsToMatcher = (globs: Array) => (path: Config.Path) => - micromatchSome(replacePathSepForGlob(path), globs, {dot: true}); + !!micromatch([replacePathSepForGlob(path)], globs, {dot: true}).length; const regexToMatcher = (testRegex: Array) => (path: Config.Path) => testRegex.some(testRegex => new RegExp(testRegex).test(path)); diff --git a/packages/jest-haste-map/src/HasteFS.ts b/packages/jest-haste-map/src/HasteFS.ts index 1f92658b3ddf..036a652a8d19 100644 --- a/packages/jest-haste-map/src/HasteFS.ts +++ b/packages/jest-haste-map/src/HasteFS.ts @@ -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'; @@ -86,7 +86,7 @@ export default class HasteFS { const files = new Set(); 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); } } diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 1dc6826fe81d..f3fb0ab5e592 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -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 @@ -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) { diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index 133c7abc0180..de2a2fb6538e 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -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'; @@ -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); diff --git a/packages/jest-transform/src/shouldInstrument.ts b/packages/jest-transform/src/shouldInstrument.ts index bf38e514e84c..90cef21dd0c6 100644 --- a/packages/jest-transform/src/shouldInstrument.ts +++ b/packages/jest-transform/src/shouldInstrument.ts @@ -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( @@ -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; } } @@ -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; }