|
4 | 4 | * This source code is licensed under the MIT license found in the |
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | | -import {Config} from '@jest/types'; |
8 | 7 | import {readConfigs} from '../index'; |
9 | 8 |
|
10 | | -let mockResult; |
11 | 9 | jest.mock('graceful-fs', () => ({ |
12 | 10 | ...jest.requireActual('fs'), |
13 | 11 | existsSync: jest.fn(() => true), |
14 | 12 | lstatSync: jest.fn(() => ({ |
15 | 13 | isDirectory: () => false, |
16 | 14 | })), |
17 | 15 | })); |
18 | | -jest.mock('../readConfigFileAndSetRootDir', () => jest.fn(() => mockResult)); |
19 | 16 |
|
20 | 17 | test('readConfigs() throws when called without project paths', async () => { |
21 | 18 | await expect( |
22 | 19 | // @ts-expect-error |
23 | 20 | readConfigs(null /* argv */, [] /* projectPaths */), |
24 | 21 | ).rejects.toThrowError('jest: No configuration found for any project.'); |
25 | 22 | }); |
26 | | - |
27 | | -test('readConfigs() loads async config file', async () => { |
28 | | - mockResult = jest.fn(async () => ({ |
29 | | - rootDir: './', |
30 | | - })); |
31 | | - await expect( |
32 | | - readConfigs( |
33 | | - <Config.Argv>{} /* argv */, |
34 | | - ['./some-jest-config-file.js'] /* projectPaths */, |
35 | | - ), |
36 | | - ).resolves.toHaveProperty('configs'); |
37 | | - expect(mockResult).toHaveBeenCalled(); |
38 | | -}); |
39 | | - |
40 | | -test('readConfigs() reject if async was rejected', async () => { |
41 | | - mockResult = jest.fn(async () => { |
42 | | - throw new Error('Some error'); |
43 | | - }); |
44 | | - await expect( |
45 | | - readConfigs( |
46 | | - <Config.Argv>{} /* argv */, |
47 | | - ['./some-jest-config-file.js'] /* projectPaths */, |
48 | | - ), |
49 | | - ).rejects.toBeTruthy(); |
50 | | - expect(mockResult).toHaveBeenCalled(); |
51 | | -}); |
0 commit comments