Skip to content

Commit e7b1e75

Browse files
authored
fix(jest-config): add mts and cts to default moduleFileExtensions config (#14369)
1 parent 6c9e286 commit e7b1e75

File tree

12 files changed

+72
-3
lines changed

12 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44

5+
- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
56
- `[@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))
67
- `[@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))
78
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))

docs/Configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const {defaults} = require('jest-config');
9292

9393
/** @type {import('jest').Config} */
9494
const config = {
95-
moduleFileExtensions: [...defaults.moduleFileExtensions, 'mts', 'cts'],
95+
moduleDirectories: [...defaults.moduleDirectories, 'bower_components'],
9696
};
9797

9898
module.exports = config;
@@ -103,7 +103,7 @@ import type {Config} from 'jest';
103103
import {defaults} from 'jest-config';
104104

105105
const config: Config = {
106-
moduleFileExtensions: [...defaults.moduleFileExtensions, 'mts'],
106+
moduleDirectories: [...defaults.moduleDirectories, 'bower_components'],
107107
};
108108

109109
export default config;
@@ -931,7 +931,7 @@ export default config;
931931

932932
### `moduleFileExtensions` \[array<string>]
933933

934-
Default: `["js", "mjs", "cjs", "jsx", "ts", "tsx", "json", "node"]`
934+
Default: `["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "json", "node"]`
935935

936936
An array of file extensions your modules use. If you require modules without specifying a file extension, these are the extensions Jest will look for, in left-to-right order.
937937

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
4040
"cjs",
4141
"jsx",
4242
"ts",
43+
"mts",
44+
"cts",
4345
"tsx",
4446
"json",
4547
"node"
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 cts and mts extension 1`] = `
4+
"Test Suites: 2 passed, 2 total
5+
Tests: 2 passed, 2 total
6+
Snapshots: 0 total
7+
Time: <<REPLACED>>
8+
Ran all test suites."
9+
`;

e2e/__tests__/testMatchTs.test.ts

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 cts and mts extension', () => {
12+
const result = runJest('test-match-ts');
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('mts 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+
});

e2e/test-match-ts/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"jest": {
3+
"testMatch": [
4+
"**/__tests__/*.?ts"
5+
]
6+
}
7+
}

packages/create-jest/src/__tests__/__snapshots__/init.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ const config: Config = {
202202
// "cjs",
203203
// "jsx",
204204
// "ts",
205+
// "mts",
206+
// "cts",
205207
// "tsx",
206208
// "json",
207209
// "node"
@@ -404,6 +406,8 @@ const config = {
404406
// "cjs",
405407
// "jsx",
406408
// "ts",
409+
// "mts",
410+
// "cts",
407411
// "tsx",
408412
// "json",
409413
// "node"
@@ -606,6 +610,8 @@ const config = {
606610
// "cjs",
607611
// "jsx",
608612
// "ts",
613+
// "mts",
614+
// "cts",
609615
// "tsx",
610616
// "json",
611617
// "node"

packages/jest-config/src/Defaults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const defaultOptions: Config.DefaultOptions = {
5151
'cjs',
5252
'jsx',
5353
'ts',
54+
'mts',
55+
'cts',
5456
'tsx',
5557
'json',
5658
'node',

0 commit comments

Comments
 (0)