-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathindex.spec.ts
More file actions
143 lines (128 loc) · 5.15 KB
/
index.spec.ts
File metadata and controls
143 lines (128 loc) · 5.15 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { expect, test } from '@voidzero-dev/vite-plus-test';
import {
configDefaults,
coverageConfigDefaults,
defaultExclude,
defaultInclude,
defaultBrowserPort,
defineConfig,
defineProject,
} from '../index.js';
test('should keep vitest exports stable', () => {
expect(defineConfig).toBeTypeOf('function');
expect(defineProject).toBeTypeOf('function');
expect(configDefaults).toBeDefined();
expect(coverageConfigDefaults).toBeDefined();
expect(defaultExclude).toBeDefined();
expect(defaultInclude).toBeDefined();
expect(defaultBrowserPort).toBeDefined();
});
test('should support lazy loading of plugins', async () => {
const config = await defineConfig({
lazy: () => Promise.resolve({ plugins: [{ name: 'test' }] }),
});
expect(config.plugins?.length).toBe(1);
});
test('should merge lazy plugins with existing plugins', async () => {
const config = await defineConfig({
plugins: [{ name: 'existing' }],
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy' }] }),
});
expect(config.plugins?.length).toBe(2);
expect((config.plugins?.[0] as { name: string })?.name).toBe('existing');
expect((config.plugins?.[1] as { name: string })?.name).toBe('lazy');
});
test('should handle lazy with empty plugins array', async () => {
const config = await defineConfig({
lazy: () => Promise.resolve({ plugins: [] }),
});
expect(config.plugins?.length).toBe(0);
});
test('should handle lazy returning undefined plugins', async () => {
const config = await defineConfig({
lazy: () => Promise.resolve({}),
});
expect(config.plugins?.length).toBe(0);
});
test('should handle Promise config with lazy', async () => {
const config = await defineConfig(
Promise.resolve({
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy-from-promise' }] }),
}),
);
expect(config.plugins?.length).toBe(1);
expect((config.plugins?.[0] as { name: string })?.name).toBe('lazy-from-promise');
});
test('should handle Promise config with lazy and existing plugins', async () => {
const config = await defineConfig(
Promise.resolve({
plugins: [{ name: 'existing' }],
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy' }] }),
}),
);
expect(config.plugins?.length).toBe(2);
expect((config.plugins?.[0] as { name: string })?.name).toBe('existing');
expect((config.plugins?.[1] as { name: string })?.name).toBe('lazy');
});
test('should handle Promise config without lazy', async () => {
const config = await defineConfig(
Promise.resolve({
plugins: [{ name: 'no-lazy' }],
}),
);
expect(config.plugins?.length).toBe(1);
expect((config.plugins?.[0] as { name: string })?.name).toBe('no-lazy');
});
test('should handle function config with lazy', async () => {
const configFn = defineConfig(() => ({
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy-from-fn' }] }),
}));
expect(typeof configFn).toBe('function');
const config = await configFn({ command: 'build', mode: 'production' });
expect(config.plugins?.length).toBe(1);
expect((config.plugins?.[0] as { name: string })?.name).toBe('lazy-from-fn');
});
test('should handle function config with lazy and existing plugins', async () => {
const configFn = defineConfig(() => ({
plugins: [{ name: 'existing' }],
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy' }] }),
}));
const config = await configFn({ command: 'build', mode: 'production' });
expect(config.plugins?.length).toBe(2);
expect((config.plugins?.[0] as { name: string })?.name).toBe('existing');
expect((config.plugins?.[1] as { name: string })?.name).toBe('lazy');
});
test('should handle function config without lazy', () => {
const configFn = defineConfig(() => ({
plugins: [{ name: 'no-lazy' }],
}));
const config = configFn({ command: 'build', mode: 'production' });
expect(config.plugins?.length).toBe(1);
expect((config.plugins?.[0] as { name: string })?.name).toBe('no-lazy');
});
test('should handle async function config with lazy', async () => {
const configFn = defineConfig(async () => ({
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy-from-async-fn' }] }),
}));
const config = await configFn({ command: 'build', mode: 'production' });
expect(config.plugins?.length).toBe(1);
expect((config.plugins?.[0] as { name: string })?.name).toBe('lazy-from-async-fn');
});
test('should handle async function config with lazy and existing plugins', async () => {
const configFn = defineConfig(async () => ({
plugins: [{ name: 'existing' }],
lazy: () => Promise.resolve({ plugins: [{ name: 'lazy' }] }),
}));
const config = await configFn({ command: 'build', mode: 'production' });
expect(config.plugins?.length).toBe(2);
expect((config.plugins?.[0] as { name: string })?.name).toBe('existing');
expect((config.plugins?.[1] as { name: string })?.name).toBe('lazy');
});
test('should handle async function config without lazy', async () => {
const configFn = defineConfig(async () => ({
plugins: [{ name: 'no-lazy' }],
}));
const config = await configFn({ command: 'build', mode: 'production' });
expect(config.plugins?.length).toBe(1);
expect((config.plugins?.[0] as { name: string })?.name).toBe('no-lazy');
});