Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## main

### Features

- `[jest-config]` Allow `testMatch` to take a string value

### Fixes

- `[expect]` Fix `bigint` error ([#15702](https://github.com/jestjs/jest/pull/15702))
Expand Down
11 changes: 7 additions & 4 deletions packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ export const initialOptions: Config.InitialOptions = {
},
testFailureExitCode: 1,
testLocationInResults: false,
testMatch: [
'**/__tests__/**/*.?([mc])[jt]s?(x)',
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
],
testMatch: multipleValidOptions(
'**/__tests__/**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
[
'**/__tests__/**/*.?([mc])[jt]s?(x)',
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
],
),
testNamePattern: 'test signature',
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: multipleValidOptions(
Expand Down
14 changes: 13 additions & 1 deletion packages/jest-config/src/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ describe('testMatch', () => {
).rejects.toThrowErrorMatchingSnapshot();
});

it('normalizes testMatch', async () => {
it('normalizes testMatch root directory', async () => {
const {options} = await normalize(
{
rootDir: '/root',
Expand All @@ -965,6 +965,18 @@ describe('testMatch', () => {

expect(options.testMatch).toEqual(['/root/**/*.js']);
});

it('normalizes testMatch to array', async () => {
const {options} = await normalize(
{
rootDir: '/root',
testMatch: '**/*.js',
},
{} as Config.Argv,
);

expect(options.testMatch).toEqual(['**/*.js']);
});
});

describe('moduleDirectories', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,12 @@
case 'moduleDirectories':
case 'testMatch':
{
const option = oldOptions[key];

Check warning on line 772 in packages/jest-config/src/normalize.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-config/src/normalize.ts#L772

Added line #L772 was not covered by tests
const rawValue =
Array.isArray(option) || option == null ? option : [option];
const replacedRootDirTags = _replaceRootDirTags(
escapeGlobCharacters(options.rootDir),
oldOptions[key],
rawValue,
);

if (replacedRootDirTags) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-schemas/src/raw-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export const InitialOptions = Type.Partial(
testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()),
testFailureExitCode: Type.Integer(),
testLocationInResults: Type.Boolean(),
testMatch: Type.Array(Type.String()),
testMatch: Type.Union([Type.String(), Type.Array(Type.String())]),
testNamePattern: Type.String(),
testPathIgnorePatterns: Type.Array(Type.String()),
testRegex: Type.Union([Type.String(), Type.Array(Type.String())]),
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export type Argv = Arguments<
testEnvironment: string;
testEnvironmentOptions: string;
testFailureExitCode: string | null | undefined;
testMatch: Array<string>;
testMatch: string | Array<string>;
testNamePattern: string;
testPathIgnorePatterns: Array<string>;
testPathPatterns: Array<string>;
Expand Down
4 changes: 2 additions & 2 deletions website/versioned_docs/version-30.0/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ This does not change the exit code in the case of Jest errors (e.g. invalid conf

:::

### `testMatch` \[array&lt;string&gt;]
### `testMatch` \[string | array&lt;string&gt;]

(default: `[ "**/__tests__/**/*.?([mc])[jt]s?(x)", "**/?(*.)+(spec|test).?([mc])[jt]s?(x)" ]`)

Expand Down Expand Up @@ -2073,7 +2073,7 @@ These pattern strings match against the full path. Use the `<rootDir>` string to

Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$`

The pattern or patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [array&lt;string&gt;]](#testmatch-arraystring), but note that you cannot specify both options.
The pattern or patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [string | array&lt;string&gt;]](#testmatch-arraystring), but note that you cannot specify both options.

The following is a visualization of the default regex:

Expand Down
Loading