/
entry.test.ts
89 lines (81 loc) · 2.68 KB
/
entry.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
84
85
86
87
88
89
jest.setMock('@webpack-cli/webpack-scaffold', {
Input: jest.fn(),
InputValidate: jest.fn(),
});
import { Input, InputValidate } from '@webpack-cli/webpack-scaffold';
// eslint-disable-next-line node/no-missing-import
import entry from '../../lib/utils/entry';
describe('entry', () => {
const InputMock = Input as jest.Mock;
const InputValidateMock = InputValidate as jest.Mock;
it('handles single entry empty string', async () => {
InputMock.mockReturnValue({
singularEntry: '',
});
expect(await entry(null, false, null)).toEqual('');
});
it('handles single entry path', async () => {
InputMock.mockReturnValue({
singularEntry: 'path/to/index',
});
expect(await entry(null, false, null)).toEqual("'./path/to/index.js'");
});
it('handles single entry path with js extension', async () => {
InputMock.mockReturnValue({
singularEntry: 'path/to/index.js',
});
expect(await entry(null, false, null)).toEqual("'./path/to/index.js'");
});
it('handles single entry relative path', async () => {
InputMock.mockReturnValue({
singularEntry: './path/to/index',
});
expect(await entry(null, false, null)).toEqual("'./path/to/index.js'");
});
it('handles multiple entry paths', async () => {
let calls = 0;
InputValidateMock.mockImplementation(() => {
calls++;
if (calls === 1) {
return {
multipleEntries: 'test1, test2',
};
} else if (calls === 2) {
return {
test1: 'src/test1',
};
} else {
return {
test2: 'src/test2',
};
}
});
expect(await entry(null, true, null)).toEqual({
test1: "'./src/test1.js'",
test2: "'./src/test2.js'",
});
});
it('handles multiple entry paths with varying formats', async () => {
let calls = 0;
InputValidateMock.mockImplementation(() => {
calls++;
if (calls === 1) {
return {
multipleEntries: ' test1 , test2 ',
};
} else if (calls === 2) {
return {
test1: './path/to/test1',
};
} else {
return {
test2: 'src/test2.js',
};
}
});
expect(await entry(null, true, null)).toEqual({
test1: "'./path/to/test1.js'",
test2: "'./src/test2.js'",
});
});
});