mirror of https://github.com/facebook/jest.git
Allow `testMatch` to take a string value (#15734)
This commit is contained in:
parent
6c6edd8949
commit
4d573817e2
|
@ -1,5 +1,9 @@
|
||||||
## main
|
## main
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- `[jest-config]` Allow `testMatch` to take a string value
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
- `[expect]` Fix `bigint` error ([#15702](https://github.com/jestjs/jest/pull/15702))
|
- `[expect]` Fix `bigint` error ([#15702](https://github.com/jestjs/jest/pull/15702))
|
||||||
|
|
|
@ -156,10 +156,13 @@ export const initialOptions: Config.InitialOptions = {
|
||||||
},
|
},
|
||||||
testFailureExitCode: 1,
|
testFailureExitCode: 1,
|
||||||
testLocationInResults: false,
|
testLocationInResults: false,
|
||||||
testMatch: [
|
testMatch: multipleValidOptions(
|
||||||
'**/__tests__/**/*.?([mc])[jt]s?(x)',
|
'**/__tests__/**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
|
||||||
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
|
[
|
||||||
],
|
'**/__tests__/**/*.?([mc])[jt]s?(x)',
|
||||||
|
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
|
||||||
|
],
|
||||||
|
),
|
||||||
testNamePattern: 'test signature',
|
testNamePattern: 'test signature',
|
||||||
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
|
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
|
||||||
testRegex: multipleValidOptions(
|
testRegex: multipleValidOptions(
|
||||||
|
|
|
@ -954,7 +954,7 @@ describe('testMatch', () => {
|
||||||
).rejects.toThrowErrorMatchingSnapshot();
|
).rejects.toThrowErrorMatchingSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('normalizes testMatch', async () => {
|
it('normalizes testMatch root directory', async () => {
|
||||||
const {options} = await normalize(
|
const {options} = await normalize(
|
||||||
{
|
{
|
||||||
rootDir: '/root',
|
rootDir: '/root',
|
||||||
|
@ -965,6 +965,18 @@ describe('testMatch', () => {
|
||||||
|
|
||||||
expect(options.testMatch).toEqual(['/root/**/*.js']);
|
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', () => {
|
describe('moduleDirectories', () => {
|
||||||
|
|
|
@ -769,9 +769,12 @@ export default async function normalize(
|
||||||
case 'moduleDirectories':
|
case 'moduleDirectories':
|
||||||
case 'testMatch':
|
case 'testMatch':
|
||||||
{
|
{
|
||||||
|
const option = oldOptions[key];
|
||||||
|
const rawValue =
|
||||||
|
Array.isArray(option) || option == null ? option : [option];
|
||||||
const replacedRootDirTags = _replaceRootDirTags(
|
const replacedRootDirTags = _replaceRootDirTags(
|
||||||
escapeGlobCharacters(options.rootDir),
|
escapeGlobCharacters(options.rootDir),
|
||||||
oldOptions[key],
|
rawValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (replacedRootDirTags) {
|
if (replacedRootDirTags) {
|
||||||
|
|
|
@ -323,7 +323,7 @@ export const InitialOptions = Type.Partial(
|
||||||
testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()),
|
testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()),
|
||||||
testFailureExitCode: Type.Integer(),
|
testFailureExitCode: Type.Integer(),
|
||||||
testLocationInResults: Type.Boolean(),
|
testLocationInResults: Type.Boolean(),
|
||||||
testMatch: Type.Array(Type.String()),
|
testMatch: Type.Union([Type.String(), Type.Array(Type.String())]),
|
||||||
testNamePattern: Type.String(),
|
testNamePattern: Type.String(),
|
||||||
testPathIgnorePatterns: Type.Array(Type.String()),
|
testPathIgnorePatterns: Type.Array(Type.String()),
|
||||||
testRegex: Type.Union([Type.String(), Type.Array(Type.String())]),
|
testRegex: Type.Union([Type.String(), Type.Array(Type.String())]),
|
||||||
|
|
|
@ -470,7 +470,7 @@ export type Argv = Arguments<
|
||||||
testEnvironment: string;
|
testEnvironment: string;
|
||||||
testEnvironmentOptions: string;
|
testEnvironmentOptions: string;
|
||||||
testFailureExitCode: string | null | undefined;
|
testFailureExitCode: string | null | undefined;
|
||||||
testMatch: Array<string>;
|
testMatch: string | Array<string>;
|
||||||
testNamePattern: string;
|
testNamePattern: string;
|
||||||
testPathIgnorePatterns: Array<string>;
|
testPathIgnorePatterns: Array<string>;
|
||||||
testPathPatterns: Array<string>;
|
testPathPatterns: Array<string>;
|
||||||
|
|
|
@ -2045,7 +2045,7 @@ This does not change the exit code in the case of Jest errors (e.g. invalid conf
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
### `testMatch` \[array<string>]
|
### `testMatch` \[string | array<string>]
|
||||||
|
|
||||||
(default: `[ "**/__tests__/**/*.?([mc])[jt]s?(x)", "**/?(*.)+(spec|test).?([mc])[jt]s?(x)" ]`)
|
(default: `[ "**/__tests__/**/*.?([mc])[jt]s?(x)", "**/?(*.)+(spec|test).?([mc])[jt]s?(x)" ]`)
|
||||||
|
|
||||||
|
@ -2073,7 +2073,7 @@ These pattern strings match against the full path. Use the `<rootDir>` string to
|
||||||
|
|
||||||
Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$`
|
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<string>]](#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<string>]](#testmatch-arraystring), but note that you cannot specify both options.
|
||||||
|
|
||||||
The following is a visualization of the default regex:
|
The following is a visualization of the default regex:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue