Add mts and cts to test match and test regex (#14584)

This commit is contained in:
Yusuke Iinuma 2023-10-02 18:11:09 +09:00 committed by GitHub
parent 85278ee979
commit a889046b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 228 additions and 19 deletions

View File

@ -160,6 +160,7 @@ module.exports = {
'e2e/failures/macros.js', 'e2e/failures/macros.js',
'e2e/test-in-root/*.js', 'e2e/test-in-root/*.js',
'e2e/test-match/test-suites/*', 'e2e/test-match/test-suites/*',
'e2e/test-match-default/dot-spec-tests/*',
'packages/test-utils/src/ConditionalTest.ts', 'packages/test-utils/src/ConditionalTest.ts',
], ],
env: {'jest/globals': true}, env: {'jest/globals': true},

View File

@ -3,6 +3,7 @@
### Features ### Features
- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369)) - `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
- `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584))
- `[@jest/core]` [**BREAKING**] Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14543](https://github.com/jestjs/jest/pull/14543)) - `[@jest/core]` [**BREAKING**] Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14543](https://github.com/jestjs/jest/pull/14543))
- `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543)) - `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825)) - `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))

View File

@ -2000,7 +2000,7 @@ This does not change the exit code in the case of Jest errors (e.g. invalid conf
### `testMatch` \[array<string>] ### `testMatch` \[array<string>]
(default: `[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]`) (default: `[ "**/__tests__/**/*.?([mc])[jt]s?(x)", "**/?(*.)+(spec|test).?([mc])[jt]s?(x)" ]`)
The glob 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`. The glob 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`.
@ -2024,7 +2024,7 @@ These pattern strings match against the full path. Use the `<rootDir>` string to
### `testRegex` \[string | array&lt;string&gt;] ### `testRegex` \[string | array&lt;string&gt;]
Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[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&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` [array&lt;string&gt;]](#testmatch-arraystring), but note that you cannot specify both options.

View File

@ -72,8 +72,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
"testEnvironmentOptions": {}, "testEnvironmentOptions": {},
"testLocationInResults": false, "testLocationInResults": false,
"testMatch": [ "testMatch": [
"**/__tests__/**/*.[jt]s?(x)", "**/__tests__/**/*.?([mc])[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)" "**/?(*.)+(spec|test).?([mc])[jt]s?(x)"
], ],
"testPathIgnorePatterns": [ "testPathIgnorePatterns": [
"/node_modules/" "/node_modules/"

View File

@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`testMatch should able to match file with \`?([mc])[jt]s?(x)\` by default 1`] = `
"Test Suites: 16 passed, 16 total
Tests: 16 passed, 16 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites."
`;

View File

@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {extractSummary} from '../Utils';
import runJest from '../runJest';
it('testMatch should able to match file with `?([mc])[jt]s?(x)` by default', () => {
const result = runJest('test-match-default');
expect(result.exitCode).toBe(0);
const {summary} = extractSummary(result.stderr);
expect(summary).toMatchSnapshot();
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('cjs extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('cts extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('js extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('jsx extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('mjs extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('mts extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('ts extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('tsx extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('cjs extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('cts extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('js extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('jsx extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('mjs extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('mts extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('ts extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
test('tsx extension', () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,3 @@
{
"jest": {}
}

View File

@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["./**/*.tsx"]
}

View File

@ -276,8 +276,8 @@ const config: Config = {
// The glob patterns Jest uses to detect test files // The glob patterns Jest uses to detect test files
// testMatch: [ // testMatch: [
// "**/__tests__/**/*.[jt]s?(x)", // "**/__tests__/**/*.?([mc])[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)" // "**/?(*.)+(spec|test).?([mc])[jt]s?(x)"
// ], // ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
@ -480,8 +480,8 @@ const config = {
// The glob patterns Jest uses to detect test files // The glob patterns Jest uses to detect test files
// testMatch: [ // testMatch: [
// "**/__tests__/**/*.[jt]s?(x)", // "**/__tests__/**/*.?([mc])[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)" // "**/?(*.)+(spec|test).?([mc])[jt]s?(x)"
// ], // ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
@ -684,8 +684,8 @@ const config = {
// The glob patterns Jest uses to detect test files // The glob patterns Jest uses to detect test files
// testMatch: [ // testMatch: [
// "**/__tests__/**/*.[jt]s?(x)", // "**/__tests__/**/*.?([mc])[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)" // "**/?(*.)+(spec|test).?([mc])[jt]s?(x)"
// ], // ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped

View File

@ -81,7 +81,10 @@ const defaultOptions: Config.DefaultOptions = {
testEnvironmentOptions: {}, testEnvironmentOptions: {},
testFailureExitCode: 1, testFailureExitCode: 1,
testLocationInResults: false, testLocationInResults: false,
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], testMatch: [
'**/__tests__/**/*.?([mc])[jt]s?(x)',
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
],
testPathIgnorePatterns: [NODE_MODULES_REGEXP], testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: [], testRegex: [],
testRunner: 'jest-circus/runner', testRunner: 'jest-circus/runner',

View File

@ -156,12 +156,18 @@ export const initialOptions: Config.InitialOptions = {
}, },
testFailureExitCode: 1, testFailureExitCode: 1,
testLocationInResults: false, testLocationInResults: false,
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], testMatch: [
'**/__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(
'(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', '(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$',
['/__tests__/\\.test\\.[jt]sx?$', '/__tests__/\\.spec\\.[jt]sx?$'], [
'/__tests__/\\.test\\.[mc]?[jt]sx?$',
'/__tests__/\\.spec\\.[mc]?[jt]sx?$',
],
), ),
testResultsProcessor: 'processor-node-module', testResultsProcessor: 'processor-node-module',
testRunner: 'circus', testRunner: 'circus',
@ -296,11 +302,17 @@ export const initialProjectOptions: Config.InitialProjectOptions = {
userAgent: 'Agent/007', userAgent: 'Agent/007',
}, },
testLocationInResults: false, testLocationInResults: false,
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], testMatch: [
'**/__tests__/**/*.?([mc])[jt]s?(x)',
'**/?(*.)+(spec|test).?([mc])[jt]s?(x)',
],
testPathIgnorePatterns: [NODE_MODULES_REGEXP], testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: multipleValidOptions( testRegex: multipleValidOptions(
'(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', '(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$',
['/__tests__/\\.test\\.[jt]sx?$', '/__tests__/\\.spec\\.[jt]sx?$'], [
'/__tests__/\\.test\\.[mc]?[jt]sx?$',
'/__tests__/\\.spec\\.[mc]?[jt]sx?$',
],
), ),
testRunner: 'circus', testRunner: 'circus',
transform: { transform: {

View File

@ -46,7 +46,7 @@ export const defaultConfig = {
snapshotSerializers: [], snapshotSerializers: [],
testEnvironment: 'jest-environment-node', testEnvironment: 'jest-environment-node',
testPathIgnorePatterns: [NODE_MODULES_REGEXP], testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$',
testResultsProcessor: null, testResultsProcessor: null,
transformIgnorePatterns: [NODE_MODULES_REGEXP], transformIgnorePatterns: [NODE_MODULES_REGEXP],
useStderr: false, useStderr: false,
@ -104,7 +104,7 @@ export const validConfig = {
testEnvironment: 'jest-environment-node', testEnvironment: 'jest-environment-node',
testNamePattern: 'test signature', testNamePattern: 'test signature',
testPathIgnorePatterns: [NODE_MODULES_REGEXP], testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$',
testResultsProcessor: 'processor-node-module', testResultsProcessor: 'processor-node-module',
testRunner: 'circus', testRunner: 'circus',
transform: { transform: {