diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b0f703e4bc..21d59d56382d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ - `[jest-config]` Support `testTimeout` in project config ([#14697](https://github.com/jestjs/jest/pull/14697)) - `[jest-config]` Support `coverageReporters` in project config ([#14697](https://github.com/jestjs/jest/pull/14830)) - `[jest-config]` Allow `reporters` in project config ([#14768](https://github.com/jestjs/jest/pull/14768)) +- `[jest-config]` Allow Node16/NodeNext/Bundler `moduleResolution` in project's tsconfig ([#14739](https://github.com/jestjs/jest/pull/14739)) - `[jest-each]` Allow `$keypath` templates with `null` or `undefined` values ([#14831](https://github.com/jestjs/jest/pull/14831)) - `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408)) - `[@jest/expect-utils]` [**BREAKING**] exclude non-enumerable in object matching ([#14670](https://github.com/jestjs/jest/pull/14670)) diff --git a/e2e/__tests__/typescriptConfigFile.test.ts b/e2e/__tests__/typescriptConfigFile.test.ts index df0e316c5bd3..d857e6bfc1d7 100644 --- a/e2e/__tests__/typescriptConfigFile.test.ts +++ b/e2e/__tests__/typescriptConfigFile.test.ts @@ -8,7 +8,7 @@ import {tmpdir} from 'os'; import * as path from 'path'; import {cleanup, writeFiles} from '../Utils'; -import runJest from '../runJest'; +import runJest, {getConfig} from '../runJest'; const DIR = path.resolve(tmpdir(), 'typescript-config-file'); @@ -107,3 +107,19 @@ test('works with multiple typescript configs that import something', () => { expect(exitCode).toBe(0); expect(stdout).toBe(''); }); + +test("works with single typescript config that does not import anything with project's moduleResolution set to Node16", () => { + const {configs} = getConfig( + 'typescript-config/modern-module-resolution', + [], + { + skipPkgJsonCheck: true, + }, + ); + + expect(configs).toHaveLength(1); + expect(configs[0].displayName).toEqual({ + color: 'white', + name: 'Config from modern ts file', + }); +}); diff --git a/e2e/typescript-config/modern-module-resolution/__tests__/test.js b/e2e/typescript-config/modern-module-resolution/__tests__/test.js new file mode 100644 index 000000000000..fc395e3a0f4a --- /dev/null +++ b/e2e/typescript-config/modern-module-resolution/__tests__/test.js @@ -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('dummy test', () => { + expect(1).toBe(1); +}); diff --git a/e2e/typescript-config/modern-module-resolution/jest.config.ts b/e2e/typescript-config/modern-module-resolution/jest.config.ts new file mode 100644 index 000000000000..995821a204f5 --- /dev/null +++ b/e2e/typescript-config/modern-module-resolution/jest.config.ts @@ -0,0 +1,12 @@ +/** + * 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. + */ + +const config = { + displayName: 'Config from modern ts file', + testEnvironment: 'node', +}; +export default config; diff --git a/e2e/typescript-config/modern-module-resolution/package.json b/e2e/typescript-config/modern-module-resolution/package.json new file mode 100644 index 000000000000..5bbefffbabee --- /dev/null +++ b/e2e/typescript-config/modern-module-resolution/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/e2e/typescript-config/modern-module-resolution/tsconfig.json b/e2e/typescript-config/modern-module-resolution/tsconfig.json new file mode 100644 index 000000000000..bdf27dc03284 --- /dev/null +++ b/e2e/typescript-config/modern-module-resolution/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "Node16", + "moduleResolution": "Node16", + "strict": true + } +} diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 84ec03e6ccc9..01ddb602dd07 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -119,6 +119,7 @@ async function registerTsNode(): Promise { return tsNode.register({ compilerOptions: { module: 'CommonJS', + moduleResolution: 'Node10', }, moduleTypes: { '**': 'cjs',