diff --git a/e2e/__tests__/tsIntegration.test.ts b/e2e/__tests__/tsIntegration.test.ts index 4c35623badf7..fcb4f2df10af 100644 --- a/e2e/__tests__/tsIntegration.test.ts +++ b/e2e/__tests__/tsIntegration.test.ts @@ -58,9 +58,9 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ - const config: Config.InitialOptions = {displayName: 'ts-object-config', verbose: true}; - export default config; + import type {Config} from '@jest/types'; + const config: Config.InitialOptions = {displayName: 'ts-object-config', verbose: true}; + export default config; `, 'package.json': '{}', }); @@ -76,7 +76,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; async function getVerbose() {return true;} export default async (): Promise => { const verbose: Config.InitialOptions['verbose'] = await getVerbose(); @@ -135,7 +135,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; const config: Config.InitialOptions = {testTimeout: '10000'}; export default config; `, @@ -154,7 +154,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; const config: Config.InitialOptions = {verbose: true}; export default get config; `, @@ -212,7 +212,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; const config: Config.InitialOptions = {displayName: 'ts-esm-object-config', verbose: true}; export default config; `, @@ -230,7 +230,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; async function getVerbose() {return true;} export default async (): Promise => { const verbose: Config.InitialOptions['verbose'] = await getVerbose(); @@ -289,7 +289,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; const config: Config.InitialOptions = {testTimeout: '10000'}; export default config; `, @@ -308,7 +308,7 @@ describe('when `Config` type is imported from "@jest/types"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from '@jest/types'; const config: Config.InitialOptions = {verbose: true}; export default get config; `, @@ -368,7 +368,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; const config: Config = {displayName: 'ts-object-config', verbose: true}; export default config; `, @@ -386,7 +386,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; async function getVerbose() {return true;} export default async (): Promise => { const verbose: Config['verbose'] = await getVerbose(); @@ -445,7 +445,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; const config: Config = {testTimeout: '10000'}; export default config; `, @@ -464,7 +464,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; const config: Config = {verbose: true}; export default get config; `, @@ -522,7 +522,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; const config: Config = {displayName: 'ts-esm-object-config', verbose: true}; export default config; `, @@ -540,7 +540,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; async function getVerbose() {return true;} export default async (): Promise => { const verbose: Config['verbose'] = await getVerbose(); @@ -599,7 +599,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; const config: Config = {testTimeout: '10000'}; export default config; `, @@ -618,7 +618,7 @@ describe('when `Config` type is imported from "jest"', () => { writeFiles(DIR, { '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", 'jest.config.cts': ` - /** @type {import('@jest/types').Config} */ + import type {Config} from 'jest'; const config: Config = {verbose: true}; export default get config; `, diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 9e618b22d794..84ec03e6ccc9 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -27,7 +27,9 @@ import { export default async function readConfigFileAndSetRootDir( configPath: string, ): Promise { - const isTS = configPath.endsWith(JEST_CONFIG_EXT_TS || JEST_CONFIG_EXT_CTS); + const isTS = + configPath.endsWith(JEST_CONFIG_EXT_TS) || + configPath.endsWith(JEST_CONFIG_EXT_CTS); const isJSON = configPath.endsWith(JEST_CONFIG_EXT_JSON); let configObject;