@react-native-harness/runtime 1.0.0-alpha.21 → 1.0.0-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +20 -2
  3. package/src/client/factory.ts +9 -2
  4. package/src/client/store.ts +16 -0
  5. package/src/expect/expect.ts +127 -0
  6. package/src/expect/index.ts +1 -123
  7. package/src/expect/matchers/toMatchImageSnapshot.ts +50 -0
  8. package/src/globals.ts +12 -0
  9. package/src/index.ts +1 -1
  10. package/src/render/TestComponentOverlay.tsx +22 -2
  11. package/src/render/index.ts +8 -6
  12. package/src/runner/context.ts +16 -0
  13. package/src/runner/factory.ts +7 -1
  14. package/src/runner/index.ts +5 -0
  15. package/src/runner/runSuite.ts +4 -0
  16. package/src/runner/types.ts +7 -1
  17. package/src/ui/ReadyScreen.tsx +1 -0
  18. package/.babelrc.js +0 -23
  19. package/assets/harness-module-system.js +0 -73
  20. package/dist/bundler/bundle.d.ts +0 -2
  21. package/dist/bundler/bundle.d.ts.map +0 -1
  22. package/dist/bundler/bundle.js +0 -21
  23. package/dist/bundler/errors.d.ts +0 -15
  24. package/dist/bundler/errors.d.ts.map +0 -1
  25. package/dist/bundler/errors.js +0 -29
  26. package/dist/bundler/evaluate.d.ts +0 -2
  27. package/dist/bundler/evaluate.d.ts.map +0 -1
  28. package/dist/bundler/evaluate.js +0 -18
  29. package/dist/bundler/factory.d.ts +0 -3
  30. package/dist/bundler/factory.d.ts.map +0 -1
  31. package/dist/bundler/factory.js +0 -36
  32. package/dist/bundler/index.d.ts +0 -4
  33. package/dist/bundler/index.d.ts.map +0 -1
  34. package/dist/bundler/index.js +0 -2
  35. package/dist/bundler/types.d.ts +0 -7
  36. package/dist/bundler/types.d.ts.map +0 -1
  37. package/dist/bundler/types.js +0 -1
  38. package/dist/client/factory.d.ts +0 -2
  39. package/dist/client/factory.d.ts.map +0 -1
  40. package/dist/client/factory.js +0 -69
  41. package/dist/client/getDeviceDescriptor.d.ts +0 -8
  42. package/dist/client/getDeviceDescriptor.d.ts.map +0 -1
  43. package/dist/client/getDeviceDescriptor.js +0 -32
  44. package/dist/client/getWSServer.d.ts +0 -2
  45. package/dist/client/getWSServer.d.ts.map +0 -1
  46. package/dist/client/getWSServer.js +0 -8
  47. package/dist/client/index.d.ts +0 -2
  48. package/dist/client/index.d.ts.map +0 -1
  49. package/dist/client/index.js +0 -1
  50. package/dist/client/setup-files.d.ts +0 -12
  51. package/dist/client/setup-files.d.ts.map +0 -1
  52. package/dist/client/setup-files.js +0 -60
  53. package/dist/collector/errors.d.ts +0 -8
  54. package/dist/collector/errors.d.ts.map +0 -1
  55. package/dist/collector/errors.js +0 -20
  56. package/dist/collector/factory.d.ts +0 -3
  57. package/dist/collector/factory.d.ts.map +0 -1
  58. package/dist/collector/factory.js +0 -25
  59. package/dist/collector/functions.d.ts +0 -22
  60. package/dist/collector/functions.d.ts.map +0 -1
  61. package/dist/collector/functions.js +0 -279
  62. package/dist/collector/index.d.ts +0 -5
  63. package/dist/collector/index.d.ts.map +0 -1
  64. package/dist/collector/index.js +0 -3
  65. package/dist/collector/types.d.ts +0 -10
  66. package/dist/collector/types.d.ts.map +0 -1
  67. package/dist/collector/types.js +0 -1
  68. package/dist/collector/validation.d.ts +0 -4
  69. package/dist/collector/validation.d.ts.map +0 -1
  70. package/dist/collector/validation.js +0 -15
  71. package/dist/constants.d.ts +0 -2
  72. package/dist/constants.d.ts.map +0 -1
  73. package/dist/constants.js +0 -1
  74. package/dist/disableHMRWhenReady.d.ts +0 -2
  75. package/dist/disableHMRWhenReady.d.ts.map +0 -1
  76. package/dist/disableHMRWhenReady.js +0 -20
  77. package/dist/entry-point.d.ts +0 -2
  78. package/dist/entry-point.d.ts.map +0 -1
  79. package/dist/entry-point.js +0 -4
  80. package/dist/errors.d.ts +0 -6
  81. package/dist/errors.d.ts.map +0 -1
  82. package/dist/errors.js +0 -13
  83. package/dist/expect/index.d.ts +0 -9
  84. package/dist/expect/index.d.ts.map +0 -1
  85. package/dist/expect/index.js +0 -73
  86. package/dist/expect/setup.d.ts +0 -2
  87. package/dist/expect/setup.d.ts.map +0 -1
  88. package/dist/expect/setup.js +0 -7
  89. package/dist/filtering/index.d.ts +0 -2
  90. package/dist/filtering/index.d.ts.map +0 -1
  91. package/dist/filtering/index.js +0 -1
  92. package/dist/filtering/testNameFilter.d.ts +0 -12
  93. package/dist/filtering/testNameFilter.d.ts.map +0 -1
  94. package/dist/filtering/testNameFilter.js +0 -56
  95. package/dist/globals.d.ts +0 -9
  96. package/dist/globals.d.ts.map +0 -1
  97. package/dist/globals.js +0 -7
  98. package/dist/index.d.ts +0 -11
  99. package/dist/index.d.ts.map +0 -1
  100. package/dist/initialize.d.ts +0 -2
  101. package/dist/initialize.d.ts.map +0 -1
  102. package/dist/initialize.js +0 -24
  103. package/dist/jest-mock.d.ts +0 -2
  104. package/dist/jest-mock.d.ts.map +0 -1
  105. package/dist/jest-mock.js +0 -25
  106. package/dist/mocker/index.d.ts +0 -2
  107. package/dist/mocker/index.d.ts.map +0 -1
  108. package/dist/mocker/index.js +0 -1
  109. package/dist/mocker/registry.d.ts +0 -6
  110. package/dist/mocker/registry.d.ts.map +0 -1
  111. package/dist/mocker/registry.js +0 -50
  112. package/dist/mocker/types.d.ts +0 -6
  113. package/dist/mocker/types.d.ts.map +0 -1
  114. package/dist/mocker/types.js +0 -1
  115. package/dist/namespace.d.ts +0 -18
  116. package/dist/namespace.d.ts.map +0 -1
  117. package/dist/namespace.js +0 -19
  118. package/dist/polyfills.d.ts +0 -11
  119. package/dist/polyfills.d.ts.map +0 -1
  120. package/dist/polyfills.js +0 -13
  121. package/dist/render/ErrorBoundary.d.ts +0 -17
  122. package/dist/render/ErrorBoundary.d.ts.map +0 -1
  123. package/dist/render/ErrorBoundary.js +0 -73
  124. package/dist/render/TestComponentOverlay.d.ts +0 -3
  125. package/dist/render/TestComponentOverlay.d.ts.map +0 -1
  126. package/dist/render/TestComponentOverlay.js +0 -36
  127. package/dist/render/cleanup.d.ts +0 -2
  128. package/dist/render/cleanup.d.ts.map +0 -1
  129. package/dist/render/cleanup.js +0 -6
  130. package/dist/render/index.d.ts +0 -6
  131. package/dist/render/index.d.ts.map +0 -1
  132. package/dist/render/index.js +0 -66
  133. package/dist/render/setup.d.ts +0 -2
  134. package/dist/render/setup.d.ts.map +0 -1
  135. package/dist/render/setup.js +0 -7
  136. package/dist/render/types.d.ts +0 -12
  137. package/dist/render/types.d.ts.map +0 -1
  138. package/dist/render/types.js +0 -1
  139. package/dist/runner/errors.d.ts +0 -11
  140. package/dist/runner/errors.d.ts.map +0 -1
  141. package/dist/runner/errors.js +0 -41
  142. package/dist/runner/factory.d.ts +0 -3
  143. package/dist/runner/factory.d.ts.map +0 -1
  144. package/dist/runner/factory.js +0 -22
  145. package/dist/runner/hooks.d.ts +0 -4
  146. package/dist/runner/hooks.d.ts.map +0 -1
  147. package/dist/runner/hooks.js +0 -39
  148. package/dist/runner/index.d.ts +0 -4
  149. package/dist/runner/index.d.ts.map +0 -1
  150. package/dist/runner/index.js +0 -2
  151. package/dist/runner/runSuite.d.ts +0 -4
  152. package/dist/runner/runSuite.d.ts.map +0 -1
  153. package/dist/runner/runSuite.js +0 -199
  154. package/dist/runner/types.d.ts +0 -13
  155. package/dist/runner/types.d.ts.map +0 -1
  156. package/dist/runner/types.js +0 -1
  157. package/dist/spy/index.d.ts +0 -2
  158. package/dist/spy/index.d.ts.map +0 -1
  159. package/dist/spy/index.js +0 -2
  160. package/dist/symbolicate.d.ts +0 -3
  161. package/dist/symbolicate.d.ts.map +0 -1
  162. package/dist/symbolicate.js +0 -19
  163. package/dist/tsconfig.lib.tsbuildinfo +0 -1
  164. package/dist/ui/ReadyScreen.d.ts +0 -2
  165. package/dist/ui/ReadyScreen.d.ts.map +0 -1
  166. package/dist/ui/ReadyScreen.js +0 -103
  167. package/dist/ui/WrongEnvironmentScreen.d.ts +0 -2
  168. package/dist/ui/WrongEnvironmentScreen.d.ts.map +0 -1
  169. package/dist/ui/WrongEnvironmentScreen.js +0 -79
  170. package/dist/ui/index.d.ts +0 -2
  171. package/dist/ui/index.d.ts.map +0 -1
  172. package/dist/ui/index.js +0 -3
  173. package/dist/ui/state.d.ts +0 -20
  174. package/dist/ui/state.d.ts.map +0 -1
  175. package/dist/ui/state.js +0 -28
  176. package/dist/utils/dev-server.d.ts +0 -2
  177. package/dist/utils/dev-server.d.ts.map +0 -1
  178. package/dist/utils/dev-server.js +0 -5
  179. package/dist/utils/emitter.d.ts +0 -16
  180. package/dist/utils/emitter.d.ts.map +0 -1
  181. package/dist/utils/emitter.js +0 -39
  182. package/dist/waitFor.d.ts +0 -21
  183. package/dist/waitFor.d.ts.map +0 -1
  184. package/dist/waitFor.js +0 -137
  185. package/eslint.config.mjs +0 -10
  186. package/src/__tests__/collector.test.ts +0 -553
  187. package/src/__tests__/error-handling.test.ts +0 -132
  188. package/src/__tests__/expect.test.ts +0 -627
  189. package/src/__tests__/initialize.test.ts +0 -24
  190. package/src/__tests__/spy.test.ts +0 -538
  191. package/tsconfig.json +0 -16
  192. package/tsconfig.lib.json +0 -33
  193. package/tsconfig.spec.json +0 -34
  194. package/tsconfig.tsbuildinfo +0 -1
  195. package/vite.config.ts +0 -27
@@ -1,553 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import * as collectorFunctions from '../collector/functions.js';
3
-
4
- const noop = () => {
5
- // Noop
6
- };
7
-
8
- describe('test collector - test case recognition', () => {
9
- it('should collect basic test cases using it()', async () => {
10
- const collectedSuite = await collectorFunctions.collectTests(() => {
11
- collectorFunctions.describe('Sample Suite', () => {
12
- collectorFunctions.it('test 1', noop);
13
- collectorFunctions.it('test 2', noop);
14
- });
15
- });
16
-
17
- expect(collectedSuite.testSuite.suites).toHaveLength(1);
18
- const sampleSuite = collectedSuite.testSuite.suites[0];
19
- expect(sampleSuite.name).toBe('Sample Suite');
20
- expect(sampleSuite.tests).toHaveLength(2);
21
- expect(sampleSuite.tests[0].name).toBe('test 1');
22
- expect(sampleSuite.tests[1].name).toBe('test 2');
23
- expect(sampleSuite.tests[0].status).toBe('active');
24
- expect(sampleSuite.tests[1].status).toBe('active');
25
- });
26
-
27
- it('should collect basic test cases using test()', async () => {
28
- const collectedSuite = await collectorFunctions.collectTests(() => {
29
- collectorFunctions.describe('Sample Suite', () => {
30
- collectorFunctions.test('test 1', noop);
31
- collectorFunctions.test('test 2', noop);
32
- });
33
- });
34
-
35
- expect(collectedSuite.testSuite.suites).toHaveLength(1);
36
- const sampleSuite = collectedSuite.testSuite.suites[0];
37
- expect(sampleSuite.tests).toHaveLength(2);
38
- expect(sampleSuite.tests[0].name).toBe('test 1');
39
- expect(sampleSuite.tests[1].name).toBe('test 2');
40
- });
41
-
42
- it('should collect async test functions', async () => {
43
- const collectedSuite = await collectorFunctions.collectTests(() => {
44
- collectorFunctions.describe('Async Suite', () => {
45
- collectorFunctions.it('async test', async () => {
46
- await new Promise((resolve) => setTimeout(resolve, 10));
47
- });
48
- });
49
- });
50
-
51
- const asyncSuite = collectedSuite.testSuite.suites[0];
52
- expect(asyncSuite.tests[0].name).toBe('async test');
53
- expect(typeof asyncSuite.tests[0].fn).toBe('function');
54
- });
55
-
56
- it('should collect tests at root level', async () => {
57
- const collectedSuite = await collectorFunctions.collectTests(() => {
58
- collectorFunctions.it('root test 1', noop);
59
- collectorFunctions.test('root test 2', noop);
60
-
61
- collectorFunctions.describe('Suite with tests', () => {
62
- collectorFunctions.it('suite test', noop);
63
- });
64
- });
65
-
66
- // Collected root suite should have the root-level tests
67
- expect(collectedSuite.testSuite.tests).toHaveLength(2);
68
- expect(collectedSuite.testSuite.tests[0].name).toBe('root test 1');
69
- expect(collectedSuite.testSuite.tests[1].name).toBe('root test 2');
70
- expect(collectedSuite.testSuite.tests[0].status).toBe('active');
71
- expect(collectedSuite.testSuite.tests[1].status).toBe('active');
72
-
73
- // Should also have the describe suite
74
- expect(collectedSuite.testSuite.suites).toHaveLength(1);
75
- expect(collectedSuite.testSuite.suites[0].tests).toHaveLength(1);
76
- expect(collectedSuite.testSuite.suites[0].tests[0].name).toBe('suite test');
77
- });
78
-
79
- it('should collect tests with modifiers at root level', async () => {
80
- const collectedSuite = await collectorFunctions.collectTests(() => {
81
- collectorFunctions.it('regular root test', noop);
82
- collectorFunctions.test.skip('skipped root test', noop);
83
- collectorFunctions.it.todo('todo root test');
84
- collectorFunctions.test.only('focused root test', noop);
85
- collectorFunctions.it('another root test', noop);
86
- });
87
-
88
- // Collected root suite should have all the tests with correct statuses
89
- expect(collectedSuite.testSuite.tests).toHaveLength(5);
90
- expect(collectedSuite.testSuite.tests[0].name).toBe('regular root test');
91
- expect(collectedSuite.testSuite.tests[0].status).toBe('skipped'); // Due to .only
92
- expect(collectedSuite.testSuite.tests[1].name).toBe('skipped root test');
93
- expect(collectedSuite.testSuite.tests[1].status).toBe('skipped');
94
- expect(collectedSuite.testSuite.tests[2].name).toBe('todo root test');
95
- expect(collectedSuite.testSuite.tests[2].status).toBe('todo');
96
- expect(collectedSuite.testSuite.tests[3].name).toBe('focused root test');
97
- expect(collectedSuite.testSuite.tests[3].status).toBe('active'); // The .only test
98
- expect(collectedSuite.testSuite.tests[4].name).toBe('another root test');
99
- expect(collectedSuite.testSuite.tests[4].status).toBe('skipped'); // Due to .only
100
- });
101
- });
102
-
103
- describe('test collector - suite recognition', () => {
104
- it('should collect nested describe blocks', async () => {
105
- const collectedSuite = await collectorFunctions.collectTests(() => {
106
- collectorFunctions.describe('Outer Suite', () => {
107
- collectorFunctions.describe('Inner Suite 1', () => {
108
- collectorFunctions.it('test 1', noop);
109
- });
110
- collectorFunctions.describe('Inner Suite 2', () => {
111
- collectorFunctions.it('test 2', noop);
112
- });
113
- });
114
- });
115
-
116
- expect(collectedSuite.testSuite.suites).toHaveLength(1);
117
- const outerSuite = collectedSuite.testSuite.suites[0];
118
- expect(outerSuite.name).toBe('Outer Suite');
119
- expect(outerSuite.suites).toHaveLength(2);
120
- expect(outerSuite.suites[0].name).toBe('Inner Suite 1');
121
- expect(outerSuite.suites[1].name).toBe('Inner Suite 2');
122
- expect(outerSuite.suites[0].tests[0].name).toBe('test 1');
123
- expect(outerSuite.suites[1].tests[0].name).toBe('test 2');
124
- });
125
-
126
- it('should collect multiple top-level describe blocks', async () => {
127
- const collectedSuite = await collectorFunctions.collectTests(() => {
128
- collectorFunctions.describe('Suite 1', () => {
129
- collectorFunctions.it('test 1', noop);
130
- });
131
- collectorFunctions.describe('Suite 2', () => {
132
- collectorFunctions.it('test 2', noop);
133
- });
134
- });
135
-
136
- expect(collectedSuite.testSuite.suites).toHaveLength(2);
137
- expect(collectedSuite.testSuite.suites[0].name).toBe('Suite 1');
138
- expect(collectedSuite.testSuite.suites[1].name).toBe('Suite 2');
139
- });
140
-
141
- it('should collect deeply nested suites', async () => {
142
- const collectedSuite = await collectorFunctions.collectTests(() => {
143
- collectorFunctions.describe('Level 1', () => {
144
- collectorFunctions.describe('Level 2', () => {
145
- collectorFunctions.describe('Level 3', () => {
146
- collectorFunctions.it('deep test', noop);
147
- });
148
- });
149
- });
150
- });
151
-
152
- const level1 = collectedSuite.testSuite.suites[0];
153
- const level2 = level1.suites[0];
154
- const level3 = level2.suites[0];
155
-
156
- expect(level1.name).toBe('Level 1');
157
- expect(level2.name).toBe('Level 2');
158
- expect(level3.name).toBe('Level 3');
159
- expect(level3.tests[0].name).toBe('deep test');
160
- });
161
- });
162
-
163
- describe('test collector - skip modifier recognition', () => {
164
- it('should collect and mark skipped tests with test.skip()', async () => {
165
- const collectedSuite = await collectorFunctions.collectTests(() => {
166
- collectorFunctions.describe('Skip Suite', () => {
167
- collectorFunctions.it('active test', noop);
168
- collectorFunctions.test.skip('skipped test', noop);
169
- collectorFunctions.it.skip('another skipped test', noop);
170
- });
171
- });
172
-
173
- const skipSuite = collectedSuite.testSuite.suites[0];
174
- expect(skipSuite.tests).toHaveLength(3);
175
- expect(skipSuite.tests[0].status).toBe('active');
176
- expect(skipSuite.tests[1].status).toBe('skipped');
177
- expect(skipSuite.tests[2].status).toBe('skipped');
178
- });
179
-
180
- it('should collect and mark skipped suites with describe.skip()', async () => {
181
- const collectedSuite = await collectorFunctions.collectTests(() => {
182
- collectorFunctions.describe('Active Suite', () => {
183
- collectorFunctions.it('active test', noop);
184
- });
185
- collectorFunctions.describe.skip('Skipped Suite', () => {
186
- collectorFunctions.it('test in skipped suite', noop);
187
- });
188
- });
189
-
190
- expect(collectedSuite.testSuite.suites).toHaveLength(2);
191
- expect(collectedSuite.testSuite.suites[0].status).toBe('active');
192
- expect(collectedSuite.testSuite.suites[1].status).toBe('skipped');
193
- });
194
-
195
- it('should collect nested skipped suites', async () => {
196
- const collectedSuite = await collectorFunctions.collectTests(() => {
197
- collectorFunctions.describe.skip('Outer Skipped', () => {
198
- collectorFunctions.describe('Inner Suite', () => {
199
- collectorFunctions.it('test', noop);
200
- });
201
- });
202
- });
203
-
204
- const outerSuite = collectedSuite.testSuite.suites[0];
205
- expect(outerSuite.status).toBe('skipped');
206
- expect(outerSuite.suites[0].tests[0].name).toBe('test');
207
- });
208
- });
209
-
210
- describe('test collector - only modifier recognition', () => {
211
- it('should collect and mark only tests and skip others with test.only()', async () => {
212
- const collectedSuite = await collectorFunctions.collectTests(() => {
213
- collectorFunctions.describe('Only Suite', () => {
214
- collectorFunctions.it('regular test 1', noop);
215
- collectorFunctions.test.only('focused test', noop);
216
- collectorFunctions.it('regular test 2', noop);
217
- });
218
- });
219
-
220
- const onlySuite = collectedSuite.testSuite.suites[0];
221
- expect(onlySuite.tests).toHaveLength(3);
222
- expect(onlySuite.tests[0].status).toBe('skipped');
223
- expect(onlySuite.tests[1].status).toBe('active');
224
- expect(onlySuite.tests[2].status).toBe('skipped');
225
- expect(onlySuite._hasFocused).toBe(true);
226
- });
227
-
228
- it('should collect multiple test.only() calls', async () => {
229
- const collectedSuite = await collectorFunctions.collectTests(() => {
230
- collectorFunctions.describe('Multiple Only Suite', () => {
231
- collectorFunctions.it('regular test', noop);
232
- collectorFunctions.test.only('focused test 1', noop);
233
- collectorFunctions.test.only('focused test 2', noop);
234
- });
235
- });
236
-
237
- const multipleSuite = collectedSuite.testSuite.suites[0];
238
- expect(multipleSuite.tests[0].status).toBe('skipped');
239
- expect(multipleSuite.tests[1].status).toBe('active'); // First only stays active
240
- expect(multipleSuite.tests[2].status).toBe('active'); // Second only also active
241
- });
242
-
243
- it('should collect and mark only suites and skip others with describe.only()', async () => {
244
- const collectedSuite = await collectorFunctions.collectTests(() => {
245
- collectorFunctions.describe('Regular Suite 1', () => {
246
- collectorFunctions.it('test 1', noop);
247
- });
248
- collectorFunctions.describe.only('Focused Suite', () => {
249
- collectorFunctions.it('focused test', noop);
250
- });
251
- collectorFunctions.describe('Regular Suite 2', () => {
252
- collectorFunctions.it('test 2', noop);
253
- });
254
- });
255
-
256
- expect(collectedSuite.testSuite.suites).toHaveLength(3);
257
- expect(collectedSuite.testSuite.suites[0].status).toBe('skipped');
258
- expect(collectedSuite.testSuite.suites[1].status).toBe('active');
259
- expect(collectedSuite.testSuite.suites[2].status).toBe('skipped');
260
- expect(collectedSuite.testSuite.suites[1]._hasFocused).toBe(true);
261
- });
262
-
263
- it('should collect nested describe.only()', async () => {
264
- const collectedSuite = await collectorFunctions.collectTests(() => {
265
- collectorFunctions.describe('Outer Suite', () => {
266
- collectorFunctions.describe('Regular Inner', () => {
267
- collectorFunctions.it('test 1', noop);
268
- });
269
- collectorFunctions.describe.only('Focused Inner', () => {
270
- collectorFunctions.it('focused test', noop);
271
- });
272
- });
273
- });
274
-
275
- const outerSuite = collectedSuite.testSuite.suites[0];
276
- expect(outerSuite.status).toBe('active');
277
- expect(outerSuite._hasFocused).toBe(true);
278
- expect(outerSuite.suites[0].status).toBe('skipped');
279
- expect(outerSuite.suites[1].status).toBe('active');
280
- });
281
- });
282
-
283
- describe('test collector - todo test recognition', () => {
284
- it('should collect and mark todo tests with test.todo()', async () => {
285
- const collectedSuite = await collectorFunctions.collectTests(() => {
286
- collectorFunctions.describe('Todo Suite', () => {
287
- collectorFunctions.it('regular test', noop);
288
- collectorFunctions.test.todo('todo test');
289
- collectorFunctions.it.todo('another todo test');
290
- });
291
- });
292
-
293
- const todoSuite = collectedSuite.testSuite.suites[0];
294
- expect(todoSuite.tests).toHaveLength(3);
295
- expect(todoSuite.tests[0].status).toBe('active');
296
- expect(todoSuite.tests[1].status).toBe('todo');
297
- expect(todoSuite.tests[2].status).toBe('todo');
298
- });
299
-
300
- it('should collect todo tests without function bodies', async () => {
301
- const collectedSuite = await collectorFunctions.collectTests(() => {
302
- collectorFunctions.describe('Todo Suite', () => {
303
- collectorFunctions.test.todo('implement this feature');
304
- });
305
- });
306
-
307
- const todoSuite = collectedSuite.testSuite.suites[0];
308
- expect(todoSuite.tests[0].name).toBe('implement this feature');
309
- expect(todoSuite.tests[0].status).toBe('todo');
310
- expect(typeof todoSuite.tests[0].fn).toBe('function');
311
- });
312
- });
313
-
314
- describe('test collector - hook recognition', () => {
315
- it('should collect beforeAll hooks', async () => {
316
- const collectedSuite = await collectorFunctions.collectTests(() => {
317
- collectorFunctions.describe('Hook Suite', () => {
318
- collectorFunctions.beforeAll(() => {
319
- // setup
320
- });
321
- collectorFunctions.beforeAll(async () => {
322
- // async setup
323
- });
324
- collectorFunctions.it('test', noop);
325
- });
326
- });
327
-
328
- const hookSuite = collectedSuite.testSuite.suites[0];
329
- expect(hookSuite.beforeAll).toHaveLength(2);
330
- expect(typeof hookSuite.beforeAll[0]).toBe('function');
331
- expect(typeof hookSuite.beforeAll[1]).toBe('function');
332
- });
333
-
334
- it('should collect afterAll hooks', async () => {
335
- const collectedSuite = await collectorFunctions.collectTests(() => {
336
- collectorFunctions.describe('Hook Suite', () => {
337
- collectorFunctions.afterAll(() => {
338
- // cleanup
339
- });
340
- collectorFunctions.it('test', noop);
341
- });
342
- });
343
-
344
- const hookSuite = collectedSuite.testSuite.suites[0];
345
- expect(hookSuite.afterAll).toHaveLength(1);
346
- expect(typeof hookSuite.afterAll[0]).toBe('function');
347
- });
348
-
349
- it('should collect beforeEach hooks', async () => {
350
- const collectedSuite = await collectorFunctions.collectTests(() => {
351
- collectorFunctions.describe('Hook Suite', () => {
352
- collectorFunctions.beforeEach(() => {
353
- // setup each
354
- });
355
- collectorFunctions.beforeEach(async () => {
356
- // async setup each
357
- });
358
- collectorFunctions.it('test', noop);
359
- });
360
- });
361
-
362
- const hookSuite = collectedSuite.testSuite.suites[0];
363
- expect(hookSuite.beforeEach).toHaveLength(2);
364
- expect(typeof hookSuite.beforeEach[0]).toBe('function');
365
- expect(typeof hookSuite.beforeEach[1]).toBe('function');
366
- });
367
-
368
- it('should collect afterEach hooks', async () => {
369
- const collectedSuite = await collectorFunctions.collectTests(() => {
370
- collectorFunctions.describe('Hook Suite', () => {
371
- collectorFunctions.afterEach(() => {
372
- // cleanup each
373
- });
374
- collectorFunctions.it('test', noop);
375
- });
376
- });
377
-
378
- const hookSuite = collectedSuite.testSuite.suites[0];
379
- expect(hookSuite.afterEach).toHaveLength(1);
380
- expect(typeof hookSuite.afterEach[0]).toBe('function');
381
- });
382
-
383
- it('should collect all types of hooks together', async () => {
384
- const collectedSuite = await collectorFunctions.collectTests(() => {
385
- collectorFunctions.describe('All Hooks Suite', () => {
386
- collectorFunctions.beforeAll(noop);
387
- collectorFunctions.afterAll(noop);
388
- collectorFunctions.beforeEach(noop);
389
- collectorFunctions.afterEach(noop);
390
- collectorFunctions.it('test', noop);
391
- });
392
- });
393
-
394
- const allHooksSuite = collectedSuite.testSuite.suites[0];
395
- expect(allHooksSuite.beforeAll).toHaveLength(1);
396
- expect(allHooksSuite.afterAll).toHaveLength(1);
397
- expect(allHooksSuite.beforeEach).toHaveLength(1);
398
- expect(allHooksSuite.afterEach).toHaveLength(1);
399
- });
400
-
401
- it('should collect hooks at root level', async () => {
402
- const collectedSuite = await collectorFunctions.collectTests(() => {
403
- collectorFunctions.beforeAll(() => {
404
- // root level setup
405
- });
406
- collectorFunctions.afterAll(() => {
407
- // root level cleanup
408
- });
409
- collectorFunctions.beforeEach(() => {
410
- // root level setup each
411
- });
412
- collectorFunctions.afterEach(() => {
413
- // root level cleanup each
414
- });
415
-
416
- collectorFunctions.describe('Test Suite', () => {
417
- collectorFunctions.it('test', noop);
418
- });
419
- });
420
-
421
- // Collected root suite should have the hooks
422
- expect(collectedSuite.testSuite.beforeAll).toHaveLength(1);
423
- expect(collectedSuite.testSuite.afterAll).toHaveLength(1);
424
- expect(collectedSuite.testSuite.beforeEach).toHaveLength(1);
425
- expect(collectedSuite.testSuite.afterEach).toHaveLength(1);
426
- expect(typeof collectedSuite.testSuite.beforeAll[0]).toBe('function');
427
- expect(typeof collectedSuite.testSuite.afterAll[0]).toBe('function');
428
- expect(typeof collectedSuite.testSuite.beforeEach[0]).toBe('function');
429
- expect(typeof collectedSuite.testSuite.afterEach[0]).toBe('function');
430
- });
431
-
432
- it('should collect hooks at both root and suite levels', async () => {
433
- const collectedSuite = await collectorFunctions.collectTests(() => {
434
- // Root level hooks
435
- collectorFunctions.beforeAll(() => {
436
- // global setup
437
- });
438
- collectorFunctions.beforeEach(() => {
439
- // global setup each
440
- });
441
-
442
- collectorFunctions.describe('Suite with hooks', () => {
443
- // Suite level hooks
444
- collectorFunctions.beforeAll(() => {
445
- // suite setup
446
- });
447
- collectorFunctions.beforeEach(() => {
448
- // suite setup each
449
- });
450
- collectorFunctions.it('test', noop);
451
- });
452
- });
453
-
454
- // Collected root suite should have its hooks
455
- expect(collectedSuite.testSuite.beforeAll).toHaveLength(1);
456
- expect(collectedSuite.testSuite.beforeEach).toHaveLength(1);
457
-
458
- // Child suite should have its own hooks
459
- const childSuite = collectedSuite.testSuite.suites[0];
460
- expect(childSuite.beforeAll).toHaveLength(1);
461
- expect(childSuite.beforeEach).toHaveLength(1);
462
- });
463
- });
464
-
465
- describe('test collector - complex scenarios', () => {
466
- it('should collect mix of tests, suites, hooks, and modifiers', async () => {
467
- const collectedSuite = await collectorFunctions.collectTests(() => {
468
- collectorFunctions.describe('Complex Suite', () => {
469
- collectorFunctions.beforeAll(noop);
470
- collectorFunctions.beforeEach(noop);
471
-
472
- collectorFunctions.it('regular test', noop);
473
- collectorFunctions.test.skip('skipped test', noop);
474
- collectorFunctions.test.todo('todo test');
475
-
476
- collectorFunctions.describe.skip('Skipped Inner Suite', () => {
477
- collectorFunctions.it('inner test', noop);
478
- });
479
-
480
- collectorFunctions.describe('Regular Inner Suite', () => {
481
- collectorFunctions.beforeEach(noop);
482
- collectorFunctions.it('inner test 1', noop);
483
- collectorFunctions.test.only('focused inner test', noop);
484
- collectorFunctions.it('inner test 2', noop);
485
- collectorFunctions.afterEach(noop);
486
- });
487
-
488
- collectorFunctions.afterAll(noop);
489
- });
490
- });
491
-
492
- const complexSuite = collectedSuite.testSuite.suites[0];
493
-
494
- // Check hooks
495
- expect(complexSuite.beforeAll).toHaveLength(1);
496
- expect(complexSuite.afterAll).toHaveLength(1);
497
- expect(complexSuite.beforeEach).toHaveLength(1);
498
-
499
- // Check tests
500
- expect(complexSuite.tests).toHaveLength(3);
501
- expect(complexSuite.tests[0].status).toBe('active');
502
- expect(complexSuite.tests[1].status).toBe('skipped');
503
- expect(complexSuite.tests[2].status).toBe('todo');
504
-
505
- // Check nested suites
506
- expect(complexSuite.suites).toHaveLength(2);
507
- expect(complexSuite.suites[0].status).toBe('skipped');
508
-
509
- const innerSuite = complexSuite.suites[1];
510
- expect(innerSuite.beforeEach).toHaveLength(1);
511
- expect(innerSuite.afterEach).toHaveLength(1);
512
- expect(innerSuite.tests).toHaveLength(3);
513
- expect(innerSuite.tests[0].status).toBe('skipped'); // Due to .only
514
- expect(innerSuite.tests[1].status).toBe('active'); // The .only test
515
- expect(innerSuite.tests[2].status).toBe('skipped'); // Due to .only
516
- });
517
-
518
- it('should clear collector state between collectTests calls', async () => {
519
- const collectedSuite1 = await collectorFunctions.collectTests(() => {
520
- collectorFunctions.describe('Suite 1', () => {
521
- collectorFunctions.it('test 1', noop);
522
- });
523
- });
524
-
525
- const collectedSuite2 = await collectorFunctions.collectTests(() => {
526
- collectorFunctions.describe('Suite 2', () => {
527
- collectorFunctions.it('test 2', noop);
528
- });
529
- });
530
-
531
- expect(collectedSuite1.testSuite.suites).toHaveLength(1);
532
- expect(collectedSuite2.testSuite.suites).toHaveLength(1);
533
- expect(collectedSuite1.testSuite.suites[0].name).toBe('Suite 1');
534
- expect(collectedSuite2.testSuite.suites[0].name).toBe('Suite 2');
535
- });
536
-
537
- it('should collect empty describe blocks', async () => {
538
- const collectedSuite = await collectorFunctions.collectTests(() => {
539
- collectorFunctions.describe('Empty Suite', () => {
540
- // No tests or hooks
541
- });
542
- });
543
-
544
- const emptySuite = collectedSuite.testSuite.suites[0];
545
- expect(emptySuite.name).toBe('Empty Suite');
546
- expect(emptySuite.tests).toHaveLength(0);
547
- expect(emptySuite.suites).toHaveLength(0);
548
- expect(emptySuite.beforeAll).toHaveLength(0);
549
- expect(emptySuite.afterAll).toHaveLength(0);
550
- expect(emptySuite.beforeEach).toHaveLength(0);
551
- expect(emptySuite.afterEach).toHaveLength(0);
552
- });
553
- });
@@ -1,132 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import * as harnessRuntime from '../collector/functions.js';
3
- import { TestError } from '../collector/errors.js';
4
-
5
- const noop = () => {
6
- // Noop
7
- };
8
-
9
- describe('error handling', () => {
10
- it('should throw TestError with proper code for invalid test names', async () => {
11
- await expect(() =>
12
- harnessRuntime.collectTests(() => {
13
- harnessRuntime.describe('Test Suite', () => {
14
- harnessRuntime.test('', noop);
15
- });
16
- })
17
- ).rejects.toThrow(TestError);
18
-
19
- await expect(() =>
20
- harnessRuntime.collectTests(() => {
21
- harnessRuntime.describe('Test Suite', () => {
22
- harnessRuntime.test(null as unknown as string, noop);
23
- });
24
- })
25
- ).rejects.toThrow(TestError);
26
- });
27
-
28
- it('should throw TestError with proper code for invalid functions', async () => {
29
- await expect(() =>
30
- harnessRuntime.collectTests(() => {
31
- harnessRuntime.describe('Test Suite', () => {
32
- // @ts-expect-error - Testing invalid input
33
- harnessRuntime.test('test name', null);
34
- });
35
- })
36
- ).rejects.toThrow(TestError);
37
- });
38
-
39
- it('should throw TestError for duplicate test names', async () => {
40
- await expect(() =>
41
- harnessRuntime.collectTests(() => {
42
- harnessRuntime.describe('Test Suite', () => {
43
- harnessRuntime.test('duplicate name', noop);
44
- harnessRuntime.test('duplicate name', noop);
45
- });
46
- })
47
- ).rejects.toThrow(TestError);
48
- });
49
-
50
- it('should throw TestError when calling test outside describe', () => {
51
- expect(() => {
52
- harnessRuntime.test('test name', noop);
53
- }).toThrow(TestError);
54
- });
55
-
56
- it('should throw TestError when calling hooks outside describe', () => {
57
- expect(() => {
58
- harnessRuntime.beforeAll(noop);
59
- }).toThrow(TestError);
60
-
61
- expect(() => {
62
- harnessRuntime.afterAll(noop);
63
- }).toThrow(TestError);
64
-
65
- expect(() => {
66
- harnessRuntime.beforeEach(noop);
67
- }).toThrow(TestError);
68
-
69
- expect(() => {
70
- harnessRuntime.afterEach(noop);
71
- }).toThrow(TestError);
72
- });
73
-
74
- it('should provide proper error context', async () => {
75
- try {
76
- await harnessRuntime.collectTests(() => {
77
- harnessRuntime.describe('Test Suite', () => {
78
- harnessRuntime.test('test1', noop);
79
- harnessRuntime.test('test1', noop);
80
- });
81
- });
82
- } catch (error) {
83
- expect(error).toBeInstanceOf(TestError);
84
- expect((error as TestError).code).toBe('DUPLICATE_TEST_NAME');
85
- expect((error as TestError).context).toEqual({
86
- name: 'test1',
87
- suiteName: 'Test Suite',
88
- });
89
- }
90
- });
91
-
92
- it('should validate describe function inputs', async () => {
93
- await expect(() =>
94
- harnessRuntime.collectTests(() => {
95
- harnessRuntime.describe('', noop);
96
- })
97
- ).rejects.toThrow(TestError);
98
-
99
- await expect(() =>
100
- harnessRuntime.collectTests(() => {
101
- // @ts-expect-error - Testing invalid input
102
- harnessRuntime.describe('Test Suite', null);
103
- })
104
- ).rejects.toThrow(TestError);
105
- });
106
-
107
- it('should validate test modifiers', async () => {
108
- await expect(() =>
109
- harnessRuntime.collectTests(() => {
110
- harnessRuntime.describe('Test Suite', () => {
111
- harnessRuntime.test.skip('', noop);
112
- });
113
- })
114
- ).rejects.toThrow(TestError);
115
-
116
- await expect(() =>
117
- harnessRuntime.collectTests(() => {
118
- harnessRuntime.describe('Test Suite', () => {
119
- harnessRuntime.test.only('', noop);
120
- });
121
- })
122
- ).rejects.toThrow(TestError);
123
-
124
- await expect(() =>
125
- harnessRuntime.collectTests(() => {
126
- harnessRuntime.describe('Test Suite', () => {
127
- harnessRuntime.test.todo('');
128
- });
129
- })
130
- ).rejects.toThrow(TestError);
131
- });
132
- });