|
1 | 1 | import { describe, expect, it } from 'vitest'; |
| 2 | +import type { TestKind } from './vitest-config-factory.js'; |
2 | 3 | import { getSetupFiles } from './vitest-setup-files.js'; |
3 | 4 |
|
4 | | -describe('vitest-setup-files', () => { |
5 | | - describe('getSetupFiles', () => { |
6 | | - describe('unit test setup files', () => { |
7 | | - it('should return all required setup files for unit tests', () => { |
8 | | - const setupFiles = getSetupFiles('unit'); |
9 | | - |
10 | | - expect(setupFiles).toHaveLength(11); |
11 | | - expect(setupFiles).toContain( |
12 | | - '../../testing/test-setup/src/lib/console.mock.ts', |
13 | | - ); |
14 | | - expect(setupFiles).toContain( |
15 | | - '../../testing/test-setup/src/lib/reset.mocks.ts', |
16 | | - ); |
17 | | - expect(setupFiles).toContain( |
18 | | - '../../testing/test-setup/src/lib/cliui.mock.ts', |
19 | | - ); |
20 | | - expect(setupFiles).toContain( |
21 | | - '../../testing/test-setup/src/lib/fs.mock.ts', |
22 | | - ); |
23 | | - expect(setupFiles).toContain( |
24 | | - '../../testing/test-setup/src/lib/git.mock.ts', |
25 | | - ); |
26 | | - expect(setupFiles).toContain( |
27 | | - '../../testing/test-setup/src/lib/portal-client.mock.ts', |
28 | | - ); |
29 | | - expect(setupFiles).toContain( |
30 | | - '../../testing/test-setup/src/lib/logger.mock.ts', |
31 | | - ); |
32 | | - expect(setupFiles).toContain( |
33 | | - '../../testing/test-setup/src/lib/extend/ui-logger.matcher.ts', |
34 | | - ); |
35 | | - expect(setupFiles).toContain( |
36 | | - '../../testing/test-setup/src/lib/extend/markdown-table.matcher.ts', |
37 | | - ); |
38 | | - expect(setupFiles).toContain( |
39 | | - '../../testing/test-setup/src/lib/extend/jest-extended.matcher.ts', |
40 | | - ); |
41 | | - expect(setupFiles).toContain( |
42 | | - '../../testing/test-setup/src/lib/extend/path.matcher.ts', |
43 | | - ); |
44 | | - }); |
45 | | - }); |
46 | | - |
47 | | - describe('integration test setup files', () => { |
48 | | - it('should return exactly 8 setup files with essential mocks and custom matchers', () => { |
49 | | - const setupFiles = getSetupFiles('int'); |
50 | | - |
51 | | - expect(setupFiles).toHaveLength(8); |
52 | | - expect(setupFiles).toContain( |
53 | | - '../../testing/test-setup/src/lib/console.mock.ts', |
54 | | - ); |
55 | | - expect(setupFiles).toContain( |
56 | | - '../../testing/test-setup/src/lib/reset.mocks.ts', |
57 | | - ); |
58 | | - expect(setupFiles).toContain( |
59 | | - '../../testing/test-setup/src/lib/chrome-path.mock.ts', |
60 | | - ); |
61 | | - expect(setupFiles).toContain( |
62 | | - '../../testing/test-setup/src/lib/logger.mock.ts', |
63 | | - ); |
64 | | - }); |
65 | | - |
66 | | - it('should include custom matchers for integration tests', () => { |
67 | | - const setupFiles = getSetupFiles('int'); |
68 | | - |
69 | | - expect(setupFiles).toContain( |
70 | | - '../../testing/test-setup/src/lib/extend/ui-logger.matcher.ts', |
71 | | - ); |
72 | | - expect(setupFiles).toContain( |
73 | | - '../../testing/test-setup/src/lib/extend/markdown-table.matcher.ts', |
74 | | - ); |
75 | | - expect(setupFiles).toContain( |
76 | | - '../../testing/test-setup/src/lib/extend/jest-extended.matcher.ts', |
77 | | - ); |
78 | | - expect(setupFiles).toContain( |
79 | | - '../../testing/test-setup/src/lib/extend/path.matcher.ts', |
80 | | - ); |
81 | | - }); |
82 | | - |
83 | | - it('should NOT include fs, cliui, git, and portal-client mocks for integration tests', () => { |
84 | | - const setupFiles = getSetupFiles('int'); |
85 | | - |
86 | | - expect(setupFiles).not.toContain( |
87 | | - '../../testing/test-setup/src/lib/fs.mock.ts', |
88 | | - ); |
89 | | - expect(setupFiles).not.toContain( |
90 | | - '../../testing/test-setup/src/lib/cliui.mock.ts', |
91 | | - ); |
92 | | - expect(setupFiles).not.toContain( |
93 | | - '../../testing/test-setup/src/lib/git.mock.ts', |
94 | | - ); |
95 | | - expect(setupFiles).not.toContain( |
96 | | - '../../testing/test-setup/src/lib/portal-client.mock.ts', |
97 | | - ); |
98 | | - }); |
99 | | - }); |
100 | | - |
101 | | - describe('e2e test setup files', () => { |
102 | | - it('should return exactly 5 setup files with minimal mocks', () => { |
103 | | - const setupFiles = getSetupFiles('e2e'); |
104 | | - |
105 | | - expect(setupFiles).toHaveLength(5); |
106 | | - expect(setupFiles).toContain( |
107 | | - '../../testing/test-setup/src/lib/reset.mocks.ts', |
108 | | - ); |
109 | | - expect(setupFiles).toContain( |
110 | | - '../../testing/test-setup/src/lib/extend/ui-logger.matcher.ts', |
111 | | - ); |
112 | | - expect(setupFiles).toContain( |
113 | | - '../../testing/test-setup/src/lib/extend/markdown-table.matcher.ts', |
114 | | - ); |
115 | | - expect(setupFiles).toContain( |
116 | | - '../../testing/test-setup/src/lib/extend/jest-extended.matcher.ts', |
117 | | - ); |
118 | | - expect(setupFiles).toContain( |
119 | | - '../../testing/test-setup/src/lib/extend/path.matcher.ts', |
120 | | - ); |
121 | | - }); |
122 | | - |
123 | | - it('should NOT include any other mocks for e2e tests', () => { |
124 | | - const setupFiles = getSetupFiles('e2e'); |
125 | | - |
126 | | - expect(setupFiles).not.toContain( |
127 | | - '../../testing/test-setup/src/lib/console.mock.ts', |
128 | | - ); |
129 | | - expect(setupFiles).not.toContain( |
130 | | - '../../testing/test-setup/src/lib/fs.mock.ts', |
131 | | - ); |
132 | | - expect(setupFiles).not.toContain( |
133 | | - '../../testing/test-setup/src/lib/git.mock.ts', |
134 | | - ); |
135 | | - expect(setupFiles).not.toContain( |
136 | | - '../../testing/test-setup/src/lib/cliui.mock.ts', |
137 | | - ); |
138 | | - expect(setupFiles).not.toContain( |
139 | | - '../../testing/test-setup/src/lib/portal-client.mock.ts', |
140 | | - ); |
141 | | - }); |
142 | | - }); |
| 5 | +describe('getSetupFiles', () => { |
| 6 | + describe('relative paths', () => { |
| 7 | + it.each<TestKind>(['unit', 'int', 'e2e'])( |
| 8 | + 'should return paths for %s-test relative to config file location', |
| 9 | + kind => { |
| 10 | + const setupFiles = getSetupFiles(kind); |
| 11 | + expect(setupFiles).toSatisfyAll<string>(path => |
| 12 | + /^\.\.\/\.\.\//.test(path), |
| 13 | + ); |
| 14 | + }, |
| 15 | + ); |
| 16 | + }); |
143 | 17 |
|
144 | | - describe('relative paths', () => { |
145 | | - it('should return paths relative to config file location', () => { |
146 | | - const unitFiles = getSetupFiles('unit'); |
147 | | - const intFiles = getSetupFiles('int'); |
148 | | - const e2eFiles = getSetupFiles('e2e'); |
| 18 | + describe('return type', () => { |
| 19 | + it('should return an array of strings', () => { |
| 20 | + const setupFiles = getSetupFiles('unit'); |
149 | 21 |
|
150 | | - [...unitFiles, ...intFiles, ...e2eFiles].forEach(path => { |
151 | | - expect(path).toMatch(/^\.\.\/\.\.\//); |
152 | | - }); |
153 | | - }); |
| 22 | + expect(Array.isArray(setupFiles)).toBe(true); |
| 23 | + expect(setupFiles).toSatisfyAll<unknown>( |
| 24 | + item => typeof item === 'string', |
| 25 | + ); |
154 | 26 | }); |
| 27 | + }); |
155 | 28 |
|
156 | | - describe('return type', () => { |
157 | | - it('should return a readonly array', () => { |
158 | | - const setupFiles = getSetupFiles('unit'); |
| 29 | + describe('test kind differences', () => { |
| 30 | + it('should return different setup files for different test kinds', () => { |
| 31 | + const unitFiles = getSetupFiles('unit'); |
| 32 | + const intFiles = getSetupFiles('int'); |
| 33 | + const e2eFiles = getSetupFiles('e2e'); |
159 | 34 |
|
160 | | - expect(Array.isArray(setupFiles)).toBe(true); |
161 | | - }); |
| 35 | + expect(unitFiles.length).not.toBe(intFiles.length); |
| 36 | + expect(intFiles.length).not.toBe(e2eFiles.length); |
| 37 | + expect(unitFiles.length).not.toBe(e2eFiles.length); |
162 | 38 | }); |
163 | 39 |
|
164 | | - describe('test kind differences', () => { |
165 | | - it('should return different setup files for different test kinds', () => { |
166 | | - const unitFiles = getSetupFiles('unit'); |
167 | | - const intFiles = getSetupFiles('int'); |
168 | | - const e2eFiles = getSetupFiles('e2e'); |
169 | | - |
170 | | - expect(unitFiles.length).not.toBe(intFiles.length); |
171 | | - expect(intFiles.length).not.toBe(e2eFiles.length); |
172 | | - expect(unitFiles.length).not.toBe(e2eFiles.length); |
173 | | - }); |
174 | | - |
175 | | - it('should show hierarchy: unit has most, e2e has least', () => { |
176 | | - const unitFiles = getSetupFiles('unit'); |
177 | | - const intFiles = getSetupFiles('int'); |
178 | | - const e2eFiles = getSetupFiles('e2e'); |
| 40 | + it('should show hierarchy: unit has most, e2e has least', () => { |
| 41 | + const unitFiles = getSetupFiles('unit'); |
| 42 | + const intFiles = getSetupFiles('int'); |
| 43 | + const e2eFiles = getSetupFiles('e2e'); |
179 | 44 |
|
180 | | - expect(unitFiles.length).toBeGreaterThan(intFiles.length); |
181 | | - expect(intFiles.length).toBeGreaterThan(e2eFiles.length); |
182 | | - }); |
| 45 | + expect(unitFiles.length).toBeGreaterThan(intFiles.length); |
| 46 | + expect(intFiles.length).toBeGreaterThan(e2eFiles.length); |
183 | 47 | }); |
184 | 48 | }); |
185 | 49 | }); |
0 commit comments