Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Store TestPathPatterns in GlobalConfig
  • Loading branch information
brandonchinn178 committed Mar 6, 2024
commit a8ca3d2dfba30c7ad476cc4f0a6b2f6c90f69ceb
2 changes: 1 addition & 1 deletion packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ export default async function normalize(

newOptions.nonFlagArgs = argv._?.map(arg => `${arg}`);
const testPathPatterns = buildTestPathPatterns(argv, options.rootDir);
newOptions.testPathPatterns = testPathPatterns.patterns;
newOptions.testPathPatterns = testPathPatterns;
newOptions.json = !!argv.json;

newOptions.testFailureExitCode = Number.parseInt(
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as os from 'os';
import * as path from 'path';
import micromatch = require('micromatch');
import type {Test, TestContext} from '@jest/test-result';
import {type Config, TestPathPatterns} from '@jest/types';
import type {Config, TestPathPatterns} from '@jest/types';
import type {ChangedFiles} from 'jest-changed-files';
import {replaceRootDirInPath} from 'jest-config';
import {escapePathForRegex} from 'jest-regex-util';
Expand Down Expand Up @@ -291,9 +291,7 @@ export default class SearchSource {
globalConfig.collectCoverage,
);
} else {
return this.findMatchingTests(
TestPathPatterns.fromGlobalConfig(globalConfig),
);
return this.findMatchingTests(globalConfig.testPathPatterns);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/__tests__/SearchSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as path from 'path';
import type {Test} from '@jest/test-result';
import type {Config} from '@jest/types';
import {type Config, TestPathPatterns} from '@jest/types';
import {normalize} from 'jest-config';
import Runtime from 'jest-runtime';
import SearchSource from '../SearchSource';
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('SearchSource', () => {
{
...config,
...initialOptions,
testPathPatterns: [],
testPathPatterns: new TestPathPatterns([]),
},
null,
filter,
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-core/src/getNoTestFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import chalk = require('chalk');
import {type Config, TestPathPatterns} from '@jest/types';
import type {Config} from '@jest/types';
import {pluralize} from 'jest-util';
import type {TestRunData} from './types';

Expand All @@ -26,9 +26,8 @@ export default function getNoTestFound(
.map(p => `"${p}"`)
.join(', ')}`;
} else {
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
dataMessage = `Pattern: ${chalk.yellow(
testPathPatterns.toPretty(),
globalConfig.testPathPatterns.toPretty(),
)} - 0 matches`;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/jest-core/src/getNoTestFoundVerbose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import chalk = require('chalk');
import {type Config, TestPathPatterns} from '@jest/types';
import type {Config} from '@jest/types';
import {pluralize} from 'jest-util';
import type {Stats, TestRunData} from './types';

Expand Down Expand Up @@ -56,9 +56,8 @@ export default function getNoTestFoundVerbose(
.map(p => `"${p}"`)
.join(', ')}`;
} else {
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
dataMessage = `Pattern: ${chalk.yellow(
testPathPatterns.toPretty(),
globalConfig.testPathPatterns.toPretty(),
)} - 0 matches`;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/lib/activeFiltersMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import chalk = require('chalk');
import {type Config, TestPathPatterns} from '@jest/types';
import type {Config} from '@jest/types';
import {isNonNullable} from 'jest-util';

const activeFilters = (globalConfig: Config.GlobalConfig): string => {
const {testNamePattern} = globalConfig;
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
const testPathPatterns = globalConfig.testPathPatterns;
if (testNamePattern || testPathPatterns.isSet()) {
const filters = [
testPathPatterns.isSet()
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/lib/updateGlobalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export default function updateGlobalConfig(
}

if (options.testPathPatterns !== undefined) {
newConfig.testPathPatterns = options.testPathPatterns;
newConfig.testPathPatterns = new TestPathPatterns(options.testPathPatterns, {rootDir: globalConfig.rootDir});
}

newConfig.onlyChanged =
!newConfig.watchAll &&
!newConfig.testNamePattern &&
!TestPathPatterns.fromGlobalConfig(newConfig).isSet();
!newConfig.testPathPatterns.isSet();

if (typeof options.bail === 'boolean') {
newConfig.bail = options.bail ? 1 : 0;
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-core/src/plugins/TestPathPattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class TestPathPatternPlugin extends BaseWatchPlugin {

testPathPatternPrompt.run(
(value: string) => {
updateConfigAndRun({mode: 'watch', testPathPatterns: [value]});
updateConfigAndRun({
mode: 'watch',
testPathPatterns: [value],
});
resolve();
},
reject,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ const usage = (
watchPlugins: Array<WatchPlugin>,
delimiter = '\n',
) => {
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
const testPathPatterns = globalConfig.testPathPatterns;
const messages = [
activeFilters(globalConfig),

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-reporters/src/SummaryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
SnapshotSummary,
TestContext,
} from '@jest/test-result';
import {type Config, TestPathPatterns} from '@jest/types';
import type {Config} from '@jest/types';
import BaseReporter from './BaseReporter';
import getResultHeader from './getResultHeader';
import getSnapshotSummary from './getSnapshotSummary';
Expand Down Expand Up @@ -211,7 +211,7 @@ export default class SummaryReporter extends BaseReporter {
testContexts: Set<TestContext>,
globalConfig: Config.GlobalConfig,
) {
const testPathPatterns = TestPathPatterns.fromGlobalConfig(globalConfig);
const testPathPatterns = globalConfig.testPathPatterns;

const getMatchingTestsInfo = () => {
const prefix = globalConfig.findRelatedTests
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {ForegroundColor} from 'chalk';
import type {ReportOptions} from 'istanbul-reports';
import type {Arguments} from 'yargs';
import type {InitialOptions, SnapshotFormat} from '@jest/schemas';
import type TestPathPatterns from './TestPathPatterns';

export type {InitialOptions} from '@jest/schemas';

Expand Down Expand Up @@ -305,7 +306,7 @@ export type GlobalConfig = {
errorOnDeprecated: boolean;
testFailureExitCode: number;
testNamePattern?: string;
testPathPatterns: Array<string>;
testPathPatterns: TestPathPatterns;
testResultsProcessor?: string;
testSequencer: string;
testTimeout?: number;
Expand Down
5 changes: 0 additions & 5 deletions packages/jest-types/src/TestPathPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';
import type * as Config from './Config';

type PatternsConfig = {
rootDir: string;
Expand All @@ -20,10 +19,6 @@ export default class TestPathPatterns {
private readonly config: PatternsConfig,
) {}

static fromGlobalConfig(globalConfig: Config.GlobalConfig): TestPathPatterns {
return new TestPathPatterns(globalConfig.testPathPatterns, globalConfig);
}

private get regexString(): string {
if (this._regexString !== null) {
return this._regexString;
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-watcher/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ export type AllowedConfigOptions = Partial<
| 'onlyFailures'
| 'reporters'
| 'testNamePattern'
| 'testPathPatterns'
| 'updateSnapshot'
| 'verbose'
> & {mode: 'watch' | 'watchAll'}
> & {
mode: 'watch' | 'watchAll';
testPathPatterns: Array<string>;
}
>;

export type UpdateConfigCallback = (config?: AllowedConfigOptions) => void;
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/src/config.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 type {Config} from '@jest/types';
import {type Config, TestPathPatterns} from '@jest/types';

const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
bail: 0,
Expand Down Expand Up @@ -55,7 +55,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
snapshotFormat: {},
testFailureExitCode: 1,
testNamePattern: '',
testPathPatterns: [],
testPathPatterns: new TestPathPatterns([], {rootDir: '/'}),
testResultsProcessor: undefined,
testSequencer: '@jest/test-sequencer',
testTimeout: 5000,
Expand Down