diff --git a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap index a6e07eaf54..fa3e71e73f 100644 --- a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap @@ -1,4 +1,17 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`falls back to a loader if we encounter a ESM TS config file in a CommonJs project 1`] = ` +"PASS __tests__/a-giraffe.js + ✓ giraffe" +`; + +exports[`falls back to a loader if we encounter a ESM TS config file in a CommonJs project 2`] = ` +"Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; exports[`on node >=24 invalid JS in jest.config.ts (node with native TS support) 1`] = ` "Error: Jest: Failed to parse the TypeScript config file <> @@ -54,19 +67,6 @@ Time: <> Ran all test suites." `; -exports[`works with jest.config.ts with cjs contents 1`] = ` -"PASS __tests__/a-giraffe.js - ✓ giraffe" -`; - -exports[`works with jest.config.ts with cjs contents 2`] = ` -"Test Suites: 1 passed, 1 total -Tests: 1 passed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites." -`; - exports[`works with tsconfig.json 1`] = ` "PASS __tests__/a-giraffe.js ✓ giraffe" diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 942a785af6..eae78332fc 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -51,7 +51,7 @@ export default async function readConfigFileAndSetRootDir( error instanceof SyntaxError && // Likely ESM in a file interpreted as CJS, which means it needs to be // compiled. We ignore the error and try to load it with a loader. - error.message.match(/Unexpected token '(export|import)'/) + /Unexpected token '(export|import)'/.test(error.message) ) ) { throw error;