From c1c53bb64c0c6e120f5a75240ce0fc5bfb2b40d3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 28 May 2021 16:13:15 +0200 Subject: [PATCH 1/3] fix: call exported config function --- packages/jest-config/src/index.ts | 8 +------- packages/jest-config/src/readConfigFileAndSetRootDir.ts | 4 ++++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index dfe12a305c01..cc0e0a702d7a 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -45,9 +45,7 @@ export async function readConfig( parentConfigDirname?: Config.Path | null, projectIndex: number = Infinity, ): Promise { - let rawOptions: - | Config.InitialOptions - | (() => Config.InitialOptions | Promise); + let rawOptions: Config.InitialOptions; let configPath = null; if (typeof packageRootOrConfig !== 'string') { @@ -87,10 +85,6 @@ export async function readConfig( rawOptions = await readConfigFileAndSetRootDir(configPath); } - if (typeof rawOptions === 'function') { - rawOptions = await rawOptions(); - } - const {options, hasDeprecationWarnings} = await normalize( rawOptions, argv, diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 953c3160be0d..5b8978fe9267 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -58,6 +58,10 @@ export default async function readConfigFileAndSetRootDir( configObject = configObject.jest || {}; } + if (typeof configObject === 'function') { + configObject = await configObject(); + } + if (configObject.rootDir) { // We don't touch it if it has an absolute path specified if (!path.isAbsolute(configObject.rootDir)) { From e853687e145015d80c1f839803ab4233af4f6bed Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 28 May 2021 16:17:58 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c07213831398..41ae1dc8acee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `[jest-circus]` Add missing `slash` dependency ([#11465](https://github.com/facebook/jest/pull/11465)) - `[jest-circus, @jest/test-sequencer]` Remove dependency on `jest-runner` ([#11466](https://github.com/facebook/jest/pull/11466)) - `[jest-config]` Resolve `config.runner` to absolute path ([#11465](https://github.com/facebook/jest/pull/11465)) +- `[jest-config]` Make sure to support functions as config ([#11475](https://github.com/facebook/jest/pull/11475)) - `[jest-core]` Do not warn about `DNSCHANNEL` handles when using the `--detectOpenHandles` option ([#11470](https://github.com/facebook/jest/pull/11470)) - `[jest-runner]` Remove dependency on `jest-config` ([#11466](https://github.com/facebook/jest/pull/11466)) - `[jest-worker]` Loosen engine requirement to `>= 10.13.0` ([#11451](https://github.com/facebook/jest/pull/11451)) From 8421d49ebd5d358d1e7c04c40879e13bb62671b6 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 28 May 2021 16:30:27 +0200 Subject: [PATCH 3/3] remove test --- .../src/__tests__/readConfigs.test.ts | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/packages/jest-config/src/__tests__/readConfigs.test.ts b/packages/jest-config/src/__tests__/readConfigs.test.ts index 349b9180da51..bdd76850552a 100644 --- a/packages/jest-config/src/__tests__/readConfigs.test.ts +++ b/packages/jest-config/src/__tests__/readConfigs.test.ts @@ -4,10 +4,8 @@ * 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 '@jest/types'; import {readConfigs} from '../index'; -let mockResult; jest.mock('graceful-fs', () => ({ ...jest.requireActual('fs'), existsSync: jest.fn(() => true), @@ -15,7 +13,6 @@ jest.mock('graceful-fs', () => ({ isDirectory: () => false, })), })); -jest.mock('../readConfigFileAndSetRootDir', () => jest.fn(() => mockResult)); test('readConfigs() throws when called without project paths', async () => { await expect( @@ -23,29 +20,3 @@ test('readConfigs() throws when called without project paths', async () => { readConfigs(null /* argv */, [] /* projectPaths */), ).rejects.toThrowError('jest: No configuration found for any project.'); }); - -test('readConfigs() loads async config file', async () => { - mockResult = jest.fn(async () => ({ - rootDir: './', - })); - await expect( - readConfigs( - {} /* argv */, - ['./some-jest-config-file.js'] /* projectPaths */, - ), - ).resolves.toHaveProperty('configs'); - expect(mockResult).toHaveBeenCalled(); -}); - -test('readConfigs() reject if async was rejected', async () => { - mockResult = jest.fn(async () => { - throw new Error('Some error'); - }); - await expect( - readConfigs( - {} /* argv */, - ['./some-jest-config-file.js'] /* projectPaths */, - ), - ).rejects.toBeTruthy(); - expect(mockResult).toHaveBeenCalled(); -});