From 7c3e57016d5513a3c488df0780d9e25db862ff2f Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 17:36:35 +0900 Subject: [PATCH 1/9] test: add `mts` and `cts` to `moduleFileExtensions` --- packages/jest-config/src/__tests__/normalize.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index afbfe417a222..3fbeac6e4b00 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', From c004324c0c355390b154d6db63cca74f3e805e39 Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 17:40:52 +0900 Subject: [PATCH 2/9] test: add e2e tests for adding `mts` and `cts` to default `moduleFileExtensions` config --- e2e/__tests__/testMatchTs.test.ts | 16 ++++++++++++++++ e2e/test-match-ts/__tests__/sample-suite.mts | 10 ++++++++++ e2e/test-match-ts/__tests__/sample-suite2.cts | 10 ++++++++++ e2e/test-match-ts/package.json | 7 +++++++ 4 files changed, 43 insertions(+) create mode 100644 e2e/__tests__/testMatchTs.test.ts create mode 100644 e2e/test-match-ts/__tests__/sample-suite.mts create mode 100644 e2e/test-match-ts/__tests__/sample-suite2.cts create mode 100644 e2e/test-match-ts/package.json 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" + ] + } +} From a5196057e4c793962060bbd5a866d1706394cf26 Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 17:47:39 +0900 Subject: [PATCH 3/9] fix: add `mts` and `cts` to `moduleFileExtensions` --- packages/jest-config/src/Defaults.ts | 2 ++ 1 file changed, 2 insertions(+) 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', From f07deb858dabbb9de9469057507052efae09048d Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 17:53:50 +0900 Subject: [PATCH 4/9] test: update snapshots --- e2e/__tests__/__snapshots__/showConfig.test.ts.snap | 2 ++ e2e/__tests__/__snapshots__/testMatchTs.test.ts.snap | 9 +++++++++ .../src/init/__tests__/__snapshots__/init.test.ts.snap | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 e2e/__tests__/__snapshots__/testMatchTs.test.ts.snap diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 24f96159efa7..5d77f17734c0 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/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.ts.snap b/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.ts.snap index f28f12ec94ca..18117e951fd4 100644 --- a/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.ts.snap +++ b/packages/jest-cli/src/init/__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" From 65e6b2ee9b2115f4e8b25be2d5fedc0b15af5027 Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 17:57:18 +0900 Subject: [PATCH 5/9] fix: add `mts` and `cts` to `moduleFileExtensions` --- packages/jest-config/src/ValidConfig.ts | 4 ++++ 1 file changed, 4 insertions(+) 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', ], From 56487528c051ca13fb0e95e01a4476eb4de2dadb Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 17:59:29 +0900 Subject: [PATCH 6/9] docs: add `mts` and `cts` to default `moduleFileExtensions` config --- docs/Configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index f60f505bef71..0b1c8d9012ef 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -930,7 +930,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. From 0f3e2615f5b84dd54a290d0be0c6af44eabc321b Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 18:06:22 +0900 Subject: [PATCH 7/9] docs: change examples because `moduleFileExtensions` supports `mts` and `cts` by default --- docs/Configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 0b1c8d9012ef..b9075097b08e 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; From 77e0f1f5cbae31a7f05793c0913c53c6c666c85a Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 18:33:15 +0900 Subject: [PATCH 8/9] chore: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 953ca6b204ca..446a6095c22a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369)) + ### Chore & Maintenance ### Performance From 38fca693c58432fdeda72ccababdcf4fe1c76769 Mon Sep 17 00:00:00 2001 From: yinm Date: Fri, 28 Jul 2023 19:31:32 +0900 Subject: [PATCH 9/9] chore: change category in changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 446a6095c22a..57bf87266792 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ ### Features -### Fixes - - `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369)) +### Fixes + ### Chore & Maintenance ### Performance