Skip to content

Commit a889046

Browse files
authored
Add mts and cts to test match and test regex (#14584)
1 parent 85278ee commit a889046

File tree

28 files changed

+228
-19
lines changed

28 files changed

+228
-19
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ module.exports = {
160160
'e2e/failures/macros.js',
161161
'e2e/test-in-root/*.js',
162162
'e2e/test-match/test-suites/*',
163+
'e2e/test-match-default/dot-spec-tests/*',
163164
'packages/test-utils/src/ConditionalTest.ts',
164165
],
165166
env: {'jest/globals': true},

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44

55
- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
6+
- `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584))
67
- `[@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))
78
- `[@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))
89
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))

docs/Configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ This does not change the exit code in the case of Jest errors (e.g. invalid conf
20002000

20012001
### `testMatch` \[array<string>]
20022002

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

20052005
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`.
20062006

@@ -2024,7 +2024,7 @@ These pattern strings match against the full path. Use the `<rootDir>` string to
20242024

20252025
### `testRegex` \[string | array&lt;string&gt;]
20262026

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

20292029
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.
20302030

e2e/__tests__/__snapshots__/showConfig.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
7272
"testEnvironmentOptions": {},
7373
"testLocationInResults": false,
7474
"testMatch": [
75-
"**/__tests__/**/*.[jt]s?(x)",
76-
"**/?(*.)+(spec|test).[tj]s?(x)"
75+
"**/__tests__/**/*.?([mc])[jt]s?(x)",
76+
"**/?(*.)+(spec|test).?([mc])[jt]s?(x)"
7777
],
7878
"testPathIgnorePatterns": [
7979
"/node_modules/"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`testMatch should able to match file with \`?([mc])[jt]s?(x)\` by default 1`] = `
4+
"Test Suites: 16 passed, 16 total
5+
Tests: 16 passed, 16 total
6+
Snapshots: 0 total
7+
Time: <<REPLACED>>
8+
Ran all test suites."
9+
`;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {extractSummary} from '../Utils';
9+
import runJest from '../runJest';
10+
11+
it('testMatch should able to match file with `?([mc])[jt]s?(x)` by default', () => {
12+
const result = runJest('test-match-default');
13+
expect(result.exitCode).toBe(0);
14+
const {summary} = extractSummary(result.stderr);
15+
expect(summary).toMatchSnapshot();
16+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
test('cjs extension', () => {
9+
expect(1).toBe(1);
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
test('cts extension', () => {
9+
expect(1).toBe(1);
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
test('js extension', () => {
9+
expect(1).toBe(1);
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
test('jsx extension', () => {
9+
expect(1).toBe(1);
10+
});

0 commit comments

Comments
 (0)