diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ee251183dc..9d7277fc82ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369)) - `[@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-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825)) diff --git a/docs/Configuration.md b/docs/Configuration.md index 4a95c468b3f5..813dd8c33c45 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -92,7 +92,7 @@ const {defaults} = require('jest-config'); /** @type {import('jest').Config} */ const config = { - moduleFileExtensions: [...defaults.moduleFileExtensions, 'mts', 'cts'], + moduleDirectories: [...defaults.moduleDirectories, 'bower_components'], }; module.exports = config; @@ -103,7 +103,7 @@ import type {Config} from 'jest'; import {defaults} from 'jest-config'; const config: Config = { - moduleFileExtensions: [...defaults.moduleFileExtensions, 'mts'], + moduleDirectories: [...defaults.moduleDirectories, 'bower_components'], }; export default config; @@ -931,7 +931,7 @@ export default config; ### `moduleFileExtensions` \[array<string>] -Default: `["js", "mjs", "cjs", "jsx", "ts", "tsx", "json", "node"]` +Default: `["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "json", "node"]` 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. diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 4632bacbaad4..332667b5f4fc 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -40,6 +40,8 @@ exports[`--showConfig outputs config info and exits 1`] = ` "cjs", "jsx", "ts", + "mts", + "cts", "tsx", "json", "node" diff --git a/e2e/__tests__/__snapshots__/testMatchTs.test.ts.snap b/e2e/__tests__/__snapshots__/testMatchTs.test.ts.snap new file mode 100644 index 000000000000..9af319324f07 --- /dev/null +++ b/e2e/__tests__/__snapshots__/testMatchTs.test.ts.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`testMatch should able to match file with cts and mts extension 1`] = ` +"Test Suites: 2 passed, 2 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; diff --git a/e2e/__tests__/testMatchTs.test.ts b/e2e/__tests__/testMatchTs.test.ts new file mode 100644 index 000000000000..e6af02cc5cc7 --- /dev/null +++ b/e2e/__tests__/testMatchTs.test.ts @@ -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 cts and mts extension', () => { + const result = runJest('test-match-ts'); + expect(result.exitCode).toBe(0); + const {summary} = extractSummary(result.stderr); + expect(summary).toMatchSnapshot(); +}); diff --git a/e2e/test-match-ts/__tests__/sample-suite.mts b/e2e/test-match-ts/__tests__/sample-suite.mts new file mode 100644 index 000000000000..9c58cacc90ec --- /dev/null +++ b/e2e/test-match-ts/__tests__/sample-suite.mts @@ -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); +}); diff --git a/e2e/test-match-ts/__tests__/sample-suite2.cts b/e2e/test-match-ts/__tests__/sample-suite2.cts new file mode 100644 index 000000000000..5a27bdb1cc01 --- /dev/null +++ b/e2e/test-match-ts/__tests__/sample-suite2.cts @@ -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); +}); diff --git a/e2e/test-match-ts/package.json b/e2e/test-match-ts/package.json new file mode 100644 index 000000000000..19272f0febb0 --- /dev/null +++ b/e2e/test-match-ts/package.json @@ -0,0 +1,7 @@ +{ + "jest": { + "testMatch": [ + "**/__tests__/*.?ts" + ] + } +} diff --git a/packages/create-jest/src/__tests__/__snapshots__/init.test.ts.snap b/packages/create-jest/src/__tests__/__snapshots__/init.test.ts.snap index f28f12ec94ca..18117e951fd4 100644 --- a/packages/create-jest/src/__tests__/__snapshots__/init.test.ts.snap +++ b/packages/create-jest/src/__tests__/__snapshots__/init.test.ts.snap @@ -202,6 +202,8 @@ const config: Config = { // "cjs", // "jsx", // "ts", + // "mts", + // "cts", // "tsx", // "json", // "node" @@ -404,6 +406,8 @@ const config = { // "cjs", // "jsx", // "ts", + // "mts", + // "cts", // "tsx", // "json", // "node" @@ -606,6 +610,8 @@ const config = { // "cjs", // "jsx", // "ts", + // "mts", + // "cts", // "tsx", // "json", // "node" diff --git a/packages/jest-config/src/Defaults.ts b/packages/jest-config/src/Defaults.ts index e744f9037bc1..270c08fd5920 100644 --- a/packages/jest-config/src/Defaults.ts +++ b/packages/jest-config/src/Defaults.ts @@ -51,6 +51,8 @@ const defaultOptions: Config.DefaultOptions = { 'cjs', 'jsx', 'ts', + 'mts', + 'cts', 'tsx', 'json', 'node', diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index 6acf984b41dd..95aa5de0c593 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -103,6 +103,8 @@ export const initialOptions: Config.InitialOptions = { 'json', 'jsx', 'ts', + 'mts', + 'cts', 'tsx', 'node', ], @@ -258,6 +260,8 @@ export const initialProjectOptions: Config.InitialProjectOptions = { 'json', 'jsx', 'ts', + 'mts', + 'cts', 'tsx', 'node', ], diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 968b7537a177..5ea19763d85a 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -1722,6 +1722,8 @@ describe('moduleFileExtensions', () => { 'cjs', 'jsx', 'ts', + 'mts', + 'cts', 'tsx', 'json', 'node',