Skip to content

Commit

Permalink
fix: call exported config function (#11475)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored May 28, 2021
1 parent 0927834 commit 7109b8c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 0 additions & 29 deletions packages/jest-config/src/__tests__/readConfigs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,19 @@
* 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),
lstatSync: jest.fn(() => ({
isDirectory: () => false,
})),
}));
jest.mock('../readConfigFileAndSetRootDir', () => jest.fn(() => mockResult));

test('readConfigs() throws when called without project paths', async () => {
await expect(
// @ts-expect-error
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(
<Config.Argv>{} /* 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(
<Config.Argv>{} /* argv */,
['./some-jest-config-file.js'] /* projectPaths */,
),
).rejects.toBeTruthy();
expect(mockResult).toHaveBeenCalled();
});
8 changes: 1 addition & 7 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export async function readConfig(
parentConfigDirname?: Config.Path | null,
projectIndex: number = Infinity,
): Promise<ReadConfig> {
let rawOptions:
| Config.InitialOptions
| (() => Config.InitialOptions | Promise<Config.InitialOptions>);
let rawOptions: Config.InitialOptions;
let configPath = null;

if (typeof packageRootOrConfig !== 'string') {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-config/src/readConfigFileAndSetRootDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 7109b8c

Please sign in to comment.