Skip to content

Commit de9edca

Browse files
Don't overload TestPathPatterns constructor
1 parent e228478 commit de9edca

File tree

8 files changed

+22
-29
lines changed

8 files changed

+22
-29
lines changed

packages/jest-core/src/SearchSource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ export default class SearchSource {
287287
globalConfig.collectCoverage,
288288
);
289289
} else {
290-
return this.findMatchingTests(new TestPathPatterns(globalConfig));
290+
return this.findMatchingTests(
291+
TestPathPatterns.fromGlobalConfig(globalConfig),
292+
);
291293
}
292294
}
293295

packages/jest-core/src/getNoTestFound.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function getNoTestFound(
2626
.map(p => `"${p}"`)
2727
.join(', ')}`;
2828
} else {
29-
const testPathPatterns = new TestPathPatterns(globalConfig);
29+
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
3030
dataMessage = `Pattern: ${chalk.yellow(
3131
testPathPatterns.toPretty(),
3232
)} - 0 matches`;

packages/jest-core/src/getNoTestFoundVerbose.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function getNoTestFoundVerbose(
5656
.map(p => `"${p}"`)
5757
.join(', ')}`;
5858
} else {
59-
const testPathPatterns = new TestPathPatterns(globalConfig);
59+
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
6060
dataMessage = `Pattern: ${chalk.yellow(
6161
testPathPatterns.toPretty(),
6262
)} - 0 matches`;

packages/jest-core/src/lib/activeFiltersMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TestPathPatterns, isNonNullable} from 'jest-util';
1111

1212
const activeFilters = (globalConfig: Config.GlobalConfig): string => {
1313
const {testNamePattern} = globalConfig;
14-
const testPathPatterns = new TestPathPatterns(globalConfig);
14+
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
1515
if (testNamePattern || testPathPatterns.isSet()) {
1616
const filters = [
1717
testPathPatterns.isSet()

packages/jest-core/src/lib/updateGlobalConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function updateGlobalConfig(
3838
newConfig.onlyChanged =
3939
!newConfig.watchAll &&
4040
!newConfig.testNamePattern &&
41-
!new TestPathPatterns(newConfig).isSet();
41+
!TestPathPatterns.fromGlobalConfig(newConfig).isSet();
4242

4343
if (typeof options.bail === 'boolean') {
4444
newConfig.bail = options.bail ? 1 : 0;

packages/jest-core/src/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ const usage = (
532532
watchPlugins: Array<WatchPlugin>,
533533
delimiter = '\n',
534534
) => {
535-
const testPathPatterns = new TestPathPatterns(globalConfig);
535+
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
536536
const messages = [
537537
activeFilters(globalConfig),
538538

packages/jest-reporters/src/SummaryReporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export default class SummaryReporter extends BaseReporter {
212212
testContexts: Set<TestContext>,
213213
globalConfig: Config.GlobalConfig,
214214
) {
215-
const testPathPatterns = new TestPathPatterns(globalConfig);
215+
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
216216

217217
const getMatchingTestsInfo = () => {
218218
const prefix = globalConfig.findRelatedTests

packages/jest-util/src/TestPathPatterns.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,30 @@
88
import type {Config} from '@jest/types';
99
import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';
1010

11-
type PatternsConfig = Pick<Config.GlobalConfig, 'rootDir'>;
12-
type PatternsFullConfig = PatternsConfig &
13-
Pick<Config.GlobalConfig, 'testPathPatterns'>;
11+
type PatternsConfig = {
12+
rootDir: string;
13+
};
1414

1515
export default class TestPathPatterns {
16-
readonly patterns: Array<string>;
17-
private readonly rootDir: string;
18-
1916
private _regexString: string | null = null;
2017

21-
constructor(patterns: Array<string>, config: PatternsConfig);
22-
constructor(config: PatternsFullConfig);
2318
constructor(
24-
patternsOrConfig: Array<string> | PatternsFullConfig,
25-
configArg?: PatternsConfig,
26-
) {
27-
let patterns, config;
28-
if (Array.isArray(patternsOrConfig)) {
29-
patterns = patternsOrConfig;
30-
config = configArg!;
31-
} else {
32-
patterns = patternsOrConfig.testPathPatterns;
33-
config = patternsOrConfig;
34-
}
19+
readonly patterns: Array<string>,
20+
private readonly config: PatternsConfig,
21+
) {}
3522

36-
this.patterns = patterns;
37-
this.rootDir = config.rootDir.replace(/\/*$/, '/');
23+
static fromGlobalConfig(globalConfig: Config.GlobalConfig): TestPathPatterns {
24+
return new TestPathPatterns(globalConfig.testPathPatterns, globalConfig);
3825
}
3926

4027
private get regexString(): string {
4128
if (this._regexString !== null) {
4229
return this._regexString;
4330
}
44-
const rootDirRegex = escapePathForRegex(this.rootDir);
31+
32+
const rootDir = this.config.rootDir.replace(/\/*$/, '/');
33+
const rootDirRegex = escapePathForRegex(rootDir);
34+
4535
const regexString = this.patterns
4636
.map(p => {
4737
// absolute paths passed on command line should stay same
@@ -59,6 +49,7 @@ export default class TestPathPatterns {
5949
})
6050
.map(replacePathSepForRegex)
6151
.join('|');
52+
6253
this._regexString = regexString;
6354
return regexString;
6455
}

0 commit comments

Comments
 (0)