From cf7082ee78546da59f5f6165f30c2bce538b07d1 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 14 May 2024 15:16:40 +0200 Subject: [PATCH] add test --- e2e/__tests__/esmConfigFile.test.ts | 12 ++++++++++++ e2e/esm-config/ts-modern/__tests__/test.js | 10 ++++++++++ e2e/esm-config/ts-modern/jest.config.ts | 10 ++++++++++ e2e/esm-config/ts-modern/package.json | 3 +++ e2e/esm-config/ts-modern/some-other-file.ts | 20 ++++++++++++++++++++ e2e/esm-config/ts-modern/tsconfig.json | 8 ++++++++ 6 files changed, 63 insertions(+) create mode 100644 e2e/esm-config/ts-modern/__tests__/test.js create mode 100644 e2e/esm-config/ts-modern/jest.config.ts create mode 100644 e2e/esm-config/ts-modern/package.json create mode 100644 e2e/esm-config/ts-modern/some-other-file.ts create mode 100644 e2e/esm-config/ts-modern/tsconfig.json diff --git a/e2e/__tests__/esmConfigFile.test.ts b/e2e/__tests__/esmConfigFile.test.ts index 4e1c5e8e96fe..9c42a3df41ff 100644 --- a/e2e/__tests__/esmConfigFile.test.ts +++ b/e2e/__tests__/esmConfigFile.test.ts @@ -54,3 +54,15 @@ test('reads config from ts file when package.json#type=module', () => { name: 'Config from ts file', }); }); + +test('reads config from ts file with modern resolution when package.json#type=module', () => { + const {configs} = getConfig('esm-config/ts-modern', [], { + skipPkgJsonCheck: true, + }); + + expect(configs).toHaveLength(1); + expect(configs[0].displayName).toEqual({ + color: 'white', + name: 'Config from modern ts file', + }); +}); diff --git a/e2e/esm-config/ts-modern/__tests__/test.js b/e2e/esm-config/ts-modern/__tests__/test.js new file mode 100644 index 000000000000..fc395e3a0f4a --- /dev/null +++ b/e2e/esm-config/ts-modern/__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/esm-config/ts-modern/jest.config.ts b/e2e/esm-config/ts-modern/jest.config.ts new file mode 100644 index 000000000000..e8e204f1da6b --- /dev/null +++ b/e2e/esm-config/ts-modern/jest.config.ts @@ -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. + */ + +import config from './some-other-file.js'; + +export default () => config; diff --git a/e2e/esm-config/ts-modern/package.json b/e2e/esm-config/ts-modern/package.json new file mode 100644 index 000000000000..3dbc1ca591c0 --- /dev/null +++ b/e2e/esm-config/ts-modern/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/e2e/esm-config/ts-modern/some-other-file.ts b/e2e/esm-config/ts-modern/some-other-file.ts new file mode 100644 index 000000000000..a63db08a433a --- /dev/null +++ b/e2e/esm-config/ts-modern/some-other-file.ts @@ -0,0 +1,20 @@ +/** + * 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. + */ + +// allows to make sure that `ts-node` compiles the config file without a need to build Jest types +// integration tests of Jest types run in a separate CI job through `jest.config.ts.mjs` +type DummyConfig = { + displayName: string; + testEnvironment: string; +}; + +const config: DummyConfig = { + displayName: 'Config from modern ts file', + testEnvironment: 'node', +}; + +export default config; diff --git a/e2e/esm-config/ts-modern/tsconfig.json b/e2e/esm-config/ts-modern/tsconfig.json new file mode 100644 index 000000000000..c74b8634308b --- /dev/null +++ b/e2e/esm-config/ts-modern/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "ESNext", + "moduleResolution": "bundler", + "strict": true + } +}