forked from umijs/father
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.test.ts
83 lines (67 loc) · 2.18 KB
/
config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { mockProcessExit } from 'jest-mock-process';
import path from 'path';
import * as cli from '../src/cli/cli';
import { distToMap } from './utils';
jest.mock('@umijs/utils', () => {
const originalModule = jest.requireActual('@umijs/utils');
return {
__esModule: true,
...originalModule,
// workaround for watch config file change in jest
// ref:
// - https://github.com/facebook/jest/issues/6034
// - https://github.com/umijs/umi-next/blob/e46748deab90807c8504dfe11f3bb554f4f27ac3/packages/core/src/config/config.ts#L172
// TODO: remove this when umi ready
register: {
...originalModule.register,
getFiles: () => (global.TMP_CASE_CONFIG ? [global.TMP_CASE_CONFIG] : []),
},
};
});
const mockExit = mockProcessExit();
const CASES_DIR = path.join(__dirname, 'fixtures/config');
beforeAll(() => {
process.env.FATHER_CACHE = 'none';
});
afterAll(() => {
delete process.env.APP_ROOT;
delete process.env.FATHER_CACHE;
mockExit.mockRestore();
jest.unmock('@umijs/utils');
});
test('config: cyclic extends', async () => {
// execute build
process.env.APP_ROOT = path.join(CASES_DIR, 'config-cyclic-extends');
// workaround for get config file path
global.TMP_CASE_CONFIG = path.join(process.env.APP_ROOT, '.fatherrc.ts');
await cli.run({
args: { _: ['build'], $0: 'node' },
});
// expect process.exit(1) called
expect(mockExit).toHaveBeenCalledWith(1);
// restore mock
jest.unmock('@umijs/utils');
delete global.TMP_CASE_CONFIG;
});
test('config: nonexistent extends', async () => {
// execute build
process.env.APP_ROOT = path.join(CASES_DIR, 'config-nonexistent-extends');
await cli.run({
args: { _: ['build'], $0: 'node' },
});
// expect process.exit(1) called
expect(mockExit).toHaveBeenCalledWith(1);
});
test('config: nested extends', async () => {
// execute build
process.env.APP_ROOT = path.join(CASES_DIR, 'config-nested-extends');
await cli.run({
args: { _: ['build'], $0: 'node' },
});
// prepare file map
const fileMap = distToMap(
path.join(CASES_DIR, 'config-nested-extends', 'dist'),
);
// check result
require(`${process.env.APP_ROOT}/expect`).default(fileMap);
});