forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 3
/
readConfigs.test.ts
51 lines (47 loc) · 1.46 KB
/
readConfigs.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* 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();
});