Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

- `[docs]` Update V30 migration guide to notify users on `jest.mock()` work with case-sensitive path ([#15849](https://github.com/jestjs/jest/pull/15849))
- `[deps]` Update to sinon/fake-timers v15
- `[*]` Replace remaining micromatch uses with picomatch

## 30.2.0

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"jest-watch-typeahead": "^3.0.1",
"jquery": "^3.2.1",
"js-yaml": "^4.1.1",
"micromatch": "^4.0.8",
"mock-fs": "^5.5.0",
"netlify-plugin-cache": "^1.0.3",
"node-notifier": "^10.0.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"jest-runner": "workspace:*",
"jest-util": "workspace:*",
"jest-validate": "workspace:*",
"micromatch": "^4.0.8",
"parse-json": "^5.2.0",
"pretty-format": "workspace:*",
"slash": "^3.0.0",
Expand All @@ -63,7 +62,6 @@
"devDependencies": {
"@jest/test-utils": "workspace:*",
"@types/graceful-fs": "^4.1.9",
"@types/micromatch": "^4.0.9",
"@types/parse-json": "^4.0.2",
"esbuild": "^0.25.5",
"esbuild-register": "^3.6.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import chalk from 'chalk';
import merge from 'deepmerge';
import {glob} from 'glob';
import {statSync} from 'graceful-fs';
import micromatch from 'micromatch';
import {TestPathPatterns} from '@jest/pattern';
import type {Config} from '@jest/types';
import {replacePathSepForRegex} from 'jest-regex-util';
Expand All @@ -24,6 +23,7 @@ import Resolver, {
} from 'jest-resolve';
import {
clearLine,
globsToMatcher,
replacePathSepForGlob,
requireOrImportModule,
tryRealpath,
Expand Down Expand Up @@ -1135,10 +1135,9 @@ export default async function normalize(
if (newOptions.collectCoverageFrom) {
collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => {
if (
micromatch(
[replacePathSepForGlob(path.relative(options.rootDir, filename))],
newOptions.collectCoverageFrom,
).length === 0
!globsToMatcher(newOptions.collectCoverageFrom)(
replacePathSepForGlob(path.relative(options.rootDir, filename)),
)
) {
return patterns;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
"jest-util": "workspace:*",
"jest-validate": "workspace:*",
"jest-watcher": "workspace:*",
"micromatch": "^4.0.8",
"pretty-format": "workspace:*",
"slash": "^3.0.0"
},
"devDependencies": {
"@jest/test-sequencer": "workspace:*",
"@jest/test-utils": "workspace:*",
"@types/graceful-fs": "^4.1.9",
"@types/micromatch": "^4.0.9"
"@types/graceful-fs": "^4.1.9"
},
"peerDependencies": {
"node-notifier": "^8.0.1 || ^9.0.0 || ^10.0.0"
Expand Down
11 changes: 3 additions & 8 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import * as os from 'os';
import * as path from 'path';
import micromatch from 'micromatch';
import type {TestPathPatternsExecutor} from '@jest/pattern';
import type {Test, TestContext} from '@jest/test-result';
import type {Config} from '@jest/types';
Expand Down Expand Up @@ -315,14 +314,10 @@ export default class SearchSource {
const normalizedPath = normalizePosix(
path.resolve(this._context.config.cwd, p),
);
const match = micromatch(
allFiles.map(normalizePosix),
normalizedPath,
options,
);
return match[0];
const matcher = globsToMatcher([normalizedPath], options);
return allFiles.map(normalizePosix).find(matcher);
})
.filter(Boolean)
.filter(p => p !== undefined)
.map(p => path.resolve(p));
return paths;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"jest-regex-util": "workspace:*",
"jest-util": "workspace:*",
"jest-worker": "workspace:*",
"micromatch": "^4.0.8",
"picomatch": "^4.0.3",
"walker": "^1.0.8"
},
"devDependencies": {
"@types/fb-watchman": "^2.0.5",
"@types/graceful-fs": "^4.1.9",
"@types/micromatch": "^4.0.9",
"@types/picomatch": "^4.0.0",
"slash": "^3.0.0"
},
"optionalDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-haste-map/src/watchers/FSEventsWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {EventEmitter} from 'events';
import * as path from 'path';
import anymatch, {type Matcher} from 'anymatch';
import * as fs from 'graceful-fs';
import micromatch from 'micromatch';
// @ts-expect-error -- no types
import walker from 'walker';
import {globsToMatcher} from 'jest-util';

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore: this is for CI which runs linux and might not have this
Expand Down Expand Up @@ -141,8 +141,8 @@ export class FSEventsWatcher extends EventEmitter {
return false;
}
return this.glob.length > 0
? micromatch([relativePath], this.glob, {dot: this.dot}).length > 0
: this.dot || micromatch([relativePath], '**/*').length > 0;
? globsToMatcher(this.glob, {dot: this.dot})(relativePath)
: this.dot || globsToMatcher(['**/*'])(relativePath);
}

private handleEvent(filepath: string) {
Expand Down
7 changes: 3 additions & 4 deletions packages/jest-haste-map/src/watchers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const platform = require('os').platform();
const path = require('path');
const anymatch = require('anymatch');
const micromatch = require('micromatch');
const picomatch = require('picomatch');
const walker = require('walker');

/**
Expand Down Expand Up @@ -61,9 +61,8 @@ exports.isFileIncluded = function (globs, dot, doIgnore, relativePath) {
return false;
}
return globs.length > 0
? micromatch.some(relativePath, globs, {dot})
: // eslint-disable-next-line unicorn/no-array-method-this-argument
dot || micromatch.some(relativePath, '**/*');
? globs.some(glob => picomatch(glob, {dot})(relativePath))
: dot || picomatch('**/*')(relativePath);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-message-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"@types/stack-utils": "^2.0.3",
"chalk": "^4.1.2",
"graceful-fs": "^4.2.11",
"micromatch": "^4.0.8",
"picomatch": "^4.0.3",
"pretty-format": "workspace:*",
"slash": "^3.0.0",
"stack-utils": "^2.0.6"
},
"devDependencies": {
"@types/babel__code-frame": "^7.0.6",
"@types/graceful-fs": "^4.1.9",
"@types/micromatch": "^4.0.9",
"@types/picomatch": "^4.0.0",
"tempy": "^1.0.1"
},
"publishConfig": {
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 @@ -11,7 +11,7 @@ import {types} from 'util';
import {codeFrameColumns} from '@babel/code-frame';
import chalk from 'chalk';
import * as fs from 'graceful-fs';
import micromatch from 'micromatch';
import picomatch from 'picomatch';
import slash from 'slash';
import StackUtils from 'stack-utils';
import type {Config, TestResult} from '@jest/types';
Expand Down Expand Up @@ -306,7 +306,7 @@ export const formatPath = (
if (
(config.testMatch &&
config.testMatch.length > 0 &&
micromatch([filePath], config.testMatch).length > 0) ||
picomatch(config.testMatch)(filePath)) ||
filePath === relativeTestPath
) {
filePath = chalk.reset.cyan(filePath);
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"jest-haste-map": "workspace:*",
"jest-regex-util": "workspace:*",
"jest-util": "workspace:*",
"micromatch": "^4.0.8",
"pirates": "^4.0.7",
"slash": "^3.0.0",
"write-file-atomic": "^5.0.1"
Expand All @@ -40,7 +39,6 @@
"@types/babel__core": "^7.20.5",
"@types/convert-source-map": "^2.0.3",
"@types/graceful-fs": "^4.1.9",
"@types/micromatch": "^4.0.9",
"@types/write-file-atomic": "^4.0.3",
"dedent": "^1.6.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-transform/src/shouldInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import * as path from 'path';
import micromatch from 'micromatch';
import type {Config} from '@jest/types';
import {escapePathForRegex} from 'jest-regex-util';
import {globsToMatcher, replacePathSepForGlob} from 'jest-util';
Expand Down Expand Up @@ -42,7 +41,7 @@ export default function shouldInstrument(

if (
config.forceCoverageMatch.length > 0 &&
micromatch.any(filename, config.forceCoverageMatch)
globsToMatcher(config.forceCoverageMatch)(filename)
) {
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
"chalk": "^4.1.2",
"ci-info": "^4.2.0",
"graceful-fs": "^4.2.11",
"picomatch": "^4.0.2"
"picomatch": "^4.0.3"
},
"devDependencies": {
"@types/graceful-fs": "^4.1.9",
"@types/micromatch": "^4.0.10",
"@types/picomatch": "^4.0.0",
"lodash": "^4.17.19"
"lodash": "^4.17.19",
"micromatch": "^4.0.8"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-util/src/globsToMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const globsToMatchersMap = new Map<
{isMatch: Matcher; negated: boolean}
>();

const picomatchOptions = {dot: true};

/**
* Converts a list of globs into a function that matches a path against the
* globs.
Expand All @@ -34,7 +32,11 @@ const picomatchOptions = {dot: true};
* isMatch('pizza.js'); // true
* isMatch('pizza.test.js'); // false
*/
export default function globsToMatcher(globs: Array<string>): Matcher {
export default function globsToMatcher(
globs: Array<string>,
picomatchOptions?: picomatch.PicomatchOptions,
): Matcher {
const dot = picomatchOptions?.dot ?? true;
if (globs.length === 0) {
// Since there were no globs given, we can simply have a fast path here and
// return with a very simple function.
Expand All @@ -43,7 +45,7 @@ export default function globsToMatcher(globs: Array<string>): Matcher {

const matchers = globs.map(glob => {
if (!globsToMatchersMap.has(glob)) {
const isMatch = picomatch(glob, picomatchOptions, true);
const isMatch = picomatch(glob, {dot, ...picomatchOptions}, true);

const matcher = {
isMatch,
Expand Down
Loading
Loading