Skip to content

Commit e4bd735

Browse files
authored
feat: split setup and setup after env (#18)
This pull request changes the behavior of setup files and post-environment setup files. The first group runs before test globals are set, while the latter runs afterward. This behavior will align with Jest.
1 parent 98ec401 commit e4bd735

File tree

6 files changed

+195
-159
lines changed

6 files changed

+195
-159
lines changed

packages/runtime/src/__tests__/collector.test.ts

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const noop = () => {
66
};
77

88
describe('test collector - test case recognition', () => {
9-
it('should collect basic test cases using it()', () => {
10-
const collectedSuite = collectorFunctions.collectTests(() => {
9+
it('should collect basic test cases using it()', async () => {
10+
const collectedSuite = await collectorFunctions.collectTests(() => {
1111
collectorFunctions.describe('Sample Suite', () => {
1212
collectorFunctions.it('test 1', noop);
1313
collectorFunctions.it('test 2', noop);
@@ -24,8 +24,8 @@ describe('test collector - test case recognition', () => {
2424
expect(sampleSuite.tests[1].status).toBe('active');
2525
});
2626

27-
it('should collect basic test cases using test()', () => {
28-
const collectedSuite = collectorFunctions.collectTests(() => {
27+
it('should collect basic test cases using test()', async () => {
28+
const collectedSuite = await collectorFunctions.collectTests(() => {
2929
collectorFunctions.describe('Sample Suite', () => {
3030
collectorFunctions.test('test 1', noop);
3131
collectorFunctions.test('test 2', noop);
@@ -39,8 +39,8 @@ describe('test collector - test case recognition', () => {
3939
expect(sampleSuite.tests[1].name).toBe('test 2');
4040
});
4141

42-
it('should collect async test functions', () => {
43-
const collectedSuite = collectorFunctions.collectTests(() => {
42+
it('should collect async test functions', async () => {
43+
const collectedSuite = await collectorFunctions.collectTests(() => {
4444
collectorFunctions.describe('Async Suite', () => {
4545
collectorFunctions.it('async test', async () => {
4646
await new Promise((resolve) => setTimeout(resolve, 10));
@@ -53,8 +53,8 @@ describe('test collector - test case recognition', () => {
5353
expect(typeof asyncSuite.tests[0].fn).toBe('function');
5454
});
5555

56-
it('should collect tests at root level', () => {
57-
const collectedSuite = collectorFunctions.collectTests(() => {
56+
it('should collect tests at root level', async () => {
57+
const collectedSuite = await collectorFunctions.collectTests(() => {
5858
collectorFunctions.it('root test 1', noop);
5959
collectorFunctions.test('root test 2', noop);
6060

@@ -76,8 +76,8 @@ describe('test collector - test case recognition', () => {
7676
expect(collectedSuite.testSuite.suites[0].tests[0].name).toBe('suite test');
7777
});
7878

79-
it('should collect tests with modifiers at root level', () => {
80-
const collectedSuite = collectorFunctions.collectTests(() => {
79+
it('should collect tests with modifiers at root level', async () => {
80+
const collectedSuite = await collectorFunctions.collectTests(() => {
8181
collectorFunctions.it('regular root test', noop);
8282
collectorFunctions.test.skip('skipped root test', noop);
8383
collectorFunctions.it.todo('todo root test');
@@ -101,8 +101,8 @@ describe('test collector - test case recognition', () => {
101101
});
102102

103103
describe('test collector - suite recognition', () => {
104-
it('should collect nested describe blocks', () => {
105-
const collectedSuite = collectorFunctions.collectTests(() => {
104+
it('should collect nested describe blocks', async () => {
105+
const collectedSuite = await collectorFunctions.collectTests(() => {
106106
collectorFunctions.describe('Outer Suite', () => {
107107
collectorFunctions.describe('Inner Suite 1', () => {
108108
collectorFunctions.it('test 1', noop);
@@ -123,8 +123,8 @@ describe('test collector - suite recognition', () => {
123123
expect(outerSuite.suites[1].tests[0].name).toBe('test 2');
124124
});
125125

126-
it('should collect multiple top-level describe blocks', () => {
127-
const collectedSuite = collectorFunctions.collectTests(() => {
126+
it('should collect multiple top-level describe blocks', async () => {
127+
const collectedSuite = await collectorFunctions.collectTests(() => {
128128
collectorFunctions.describe('Suite 1', () => {
129129
collectorFunctions.it('test 1', noop);
130130
});
@@ -138,8 +138,8 @@ describe('test collector - suite recognition', () => {
138138
expect(collectedSuite.testSuite.suites[1].name).toBe('Suite 2');
139139
});
140140

141-
it('should collect deeply nested suites', () => {
142-
const collectedSuite = collectorFunctions.collectTests(() => {
141+
it('should collect deeply nested suites', async () => {
142+
const collectedSuite = await collectorFunctions.collectTests(() => {
143143
collectorFunctions.describe('Level 1', () => {
144144
collectorFunctions.describe('Level 2', () => {
145145
collectorFunctions.describe('Level 3', () => {
@@ -161,8 +161,8 @@ describe('test collector - suite recognition', () => {
161161
});
162162

163163
describe('test collector - skip modifier recognition', () => {
164-
it('should collect and mark skipped tests with test.skip()', () => {
165-
const collectedSuite = collectorFunctions.collectTests(() => {
164+
it('should collect and mark skipped tests with test.skip()', async () => {
165+
const collectedSuite = await collectorFunctions.collectTests(() => {
166166
collectorFunctions.describe('Skip Suite', () => {
167167
collectorFunctions.it('active test', noop);
168168
collectorFunctions.test.skip('skipped test', noop);
@@ -177,8 +177,8 @@ describe('test collector - skip modifier recognition', () => {
177177
expect(skipSuite.tests[2].status).toBe('skipped');
178178
});
179179

180-
it('should collect and mark skipped suites with describe.skip()', () => {
181-
const collectedSuite = collectorFunctions.collectTests(() => {
180+
it('should collect and mark skipped suites with describe.skip()', async () => {
181+
const collectedSuite = await collectorFunctions.collectTests(() => {
182182
collectorFunctions.describe('Active Suite', () => {
183183
collectorFunctions.it('active test', noop);
184184
});
@@ -192,8 +192,8 @@ describe('test collector - skip modifier recognition', () => {
192192
expect(collectedSuite.testSuite.suites[1].status).toBe('skipped');
193193
});
194194

195-
it('should collect nested skipped suites', () => {
196-
const collectedSuite = collectorFunctions.collectTests(() => {
195+
it('should collect nested skipped suites', async () => {
196+
const collectedSuite = await collectorFunctions.collectTests(() => {
197197
collectorFunctions.describe.skip('Outer Skipped', () => {
198198
collectorFunctions.describe('Inner Suite', () => {
199199
collectorFunctions.it('test', noop);
@@ -208,8 +208,8 @@ describe('test collector - skip modifier recognition', () => {
208208
});
209209

210210
describe('test collector - only modifier recognition', () => {
211-
it('should collect and mark only tests and skip others with test.only()', () => {
212-
const collectedSuite = collectorFunctions.collectTests(() => {
211+
it('should collect and mark only tests and skip others with test.only()', async () => {
212+
const collectedSuite = await collectorFunctions.collectTests(() => {
213213
collectorFunctions.describe('Only Suite', () => {
214214
collectorFunctions.it('regular test 1', noop);
215215
collectorFunctions.test.only('focused test', noop);
@@ -225,8 +225,8 @@ describe('test collector - only modifier recognition', () => {
225225
expect(onlySuite._hasFocused).toBe(true);
226226
});
227227

228-
it('should collect multiple test.only() calls', () => {
229-
const collectedSuite = collectorFunctions.collectTests(() => {
228+
it('should collect multiple test.only() calls', async () => {
229+
const collectedSuite = await collectorFunctions.collectTests(() => {
230230
collectorFunctions.describe('Multiple Only Suite', () => {
231231
collectorFunctions.it('regular test', noop);
232232
collectorFunctions.test.only('focused test 1', noop);
@@ -240,8 +240,8 @@ describe('test collector - only modifier recognition', () => {
240240
expect(multipleSuite.tests[2].status).toBe('active'); // Second only also active
241241
});
242242

243-
it('should collect and mark only suites and skip others with describe.only()', () => {
244-
const collectedSuite = collectorFunctions.collectTests(() => {
243+
it('should collect and mark only suites and skip others with describe.only()', async () => {
244+
const collectedSuite = await collectorFunctions.collectTests(() => {
245245
collectorFunctions.describe('Regular Suite 1', () => {
246246
collectorFunctions.it('test 1', noop);
247247
});
@@ -260,8 +260,8 @@ describe('test collector - only modifier recognition', () => {
260260
expect(collectedSuite.testSuite.suites[1]._hasFocused).toBe(true);
261261
});
262262

263-
it('should collect nested describe.only()', () => {
264-
const collectedSuite = collectorFunctions.collectTests(() => {
263+
it('should collect nested describe.only()', async () => {
264+
const collectedSuite = await collectorFunctions.collectTests(() => {
265265
collectorFunctions.describe('Outer Suite', () => {
266266
collectorFunctions.describe('Regular Inner', () => {
267267
collectorFunctions.it('test 1', noop);
@@ -281,8 +281,8 @@ describe('test collector - only modifier recognition', () => {
281281
});
282282

283283
describe('test collector - todo test recognition', () => {
284-
it('should collect and mark todo tests with test.todo()', () => {
285-
const collectedSuite = collectorFunctions.collectTests(() => {
284+
it('should collect and mark todo tests with test.todo()', async () => {
285+
const collectedSuite = await collectorFunctions.collectTests(() => {
286286
collectorFunctions.describe('Todo Suite', () => {
287287
collectorFunctions.it('regular test', noop);
288288
collectorFunctions.test.todo('todo test');
@@ -297,8 +297,8 @@ describe('test collector - todo test recognition', () => {
297297
expect(todoSuite.tests[2].status).toBe('todo');
298298
});
299299

300-
it('should collect todo tests without function bodies', () => {
301-
const collectedSuite = collectorFunctions.collectTests(() => {
300+
it('should collect todo tests without function bodies', async () => {
301+
const collectedSuite = await collectorFunctions.collectTests(() => {
302302
collectorFunctions.describe('Todo Suite', () => {
303303
collectorFunctions.test.todo('implement this feature');
304304
});
@@ -312,8 +312,8 @@ describe('test collector - todo test recognition', () => {
312312
});
313313

314314
describe('test collector - hook recognition', () => {
315-
it('should collect beforeAll hooks', () => {
316-
const collectedSuite = collectorFunctions.collectTests(() => {
315+
it('should collect beforeAll hooks', async () => {
316+
const collectedSuite = await collectorFunctions.collectTests(() => {
317317
collectorFunctions.describe('Hook Suite', () => {
318318
collectorFunctions.beforeAll(() => {
319319
// setup
@@ -331,8 +331,8 @@ describe('test collector - hook recognition', () => {
331331
expect(typeof hookSuite.beforeAll[1]).toBe('function');
332332
});
333333

334-
it('should collect afterAll hooks', () => {
335-
const collectedSuite = collectorFunctions.collectTests(() => {
334+
it('should collect afterAll hooks', async () => {
335+
const collectedSuite = await collectorFunctions.collectTests(() => {
336336
collectorFunctions.describe('Hook Suite', () => {
337337
collectorFunctions.afterAll(() => {
338338
// cleanup
@@ -346,8 +346,8 @@ describe('test collector - hook recognition', () => {
346346
expect(typeof hookSuite.afterAll[0]).toBe('function');
347347
});
348348

349-
it('should collect beforeEach hooks', () => {
350-
const collectedSuite = collectorFunctions.collectTests(() => {
349+
it('should collect beforeEach hooks', async () => {
350+
const collectedSuite = await collectorFunctions.collectTests(() => {
351351
collectorFunctions.describe('Hook Suite', () => {
352352
collectorFunctions.beforeEach(() => {
353353
// setup each
@@ -365,8 +365,8 @@ describe('test collector - hook recognition', () => {
365365
expect(typeof hookSuite.beforeEach[1]).toBe('function');
366366
});
367367

368-
it('should collect afterEach hooks', () => {
369-
const collectedSuite = collectorFunctions.collectTests(() => {
368+
it('should collect afterEach hooks', async () => {
369+
const collectedSuite = await collectorFunctions.collectTests(() => {
370370
collectorFunctions.describe('Hook Suite', () => {
371371
collectorFunctions.afterEach(() => {
372372
// cleanup each
@@ -380,8 +380,8 @@ describe('test collector - hook recognition', () => {
380380
expect(typeof hookSuite.afterEach[0]).toBe('function');
381381
});
382382

383-
it('should collect all types of hooks together', () => {
384-
const collectedSuite = collectorFunctions.collectTests(() => {
383+
it('should collect all types of hooks together', async () => {
384+
const collectedSuite = await collectorFunctions.collectTests(() => {
385385
collectorFunctions.describe('All Hooks Suite', () => {
386386
collectorFunctions.beforeAll(noop);
387387
collectorFunctions.afterAll(noop);
@@ -398,8 +398,8 @@ describe('test collector - hook recognition', () => {
398398
expect(allHooksSuite.afterEach).toHaveLength(1);
399399
});
400400

401-
it('should collect hooks at root level', () => {
402-
const collectedSuite = collectorFunctions.collectTests(() => {
401+
it('should collect hooks at root level', async () => {
402+
const collectedSuite = await collectorFunctions.collectTests(() => {
403403
collectorFunctions.beforeAll(() => {
404404
// root level setup
405405
});
@@ -429,8 +429,8 @@ describe('test collector - hook recognition', () => {
429429
expect(typeof collectedSuite.testSuite.afterEach[0]).toBe('function');
430430
});
431431

432-
it('should collect hooks at both root and suite levels', () => {
433-
const collectedSuite = collectorFunctions.collectTests(() => {
432+
it('should collect hooks at both root and suite levels', async () => {
433+
const collectedSuite = await collectorFunctions.collectTests(() => {
434434
// Root level hooks
435435
collectorFunctions.beforeAll(() => {
436436
// global setup
@@ -463,8 +463,8 @@ describe('test collector - hook recognition', () => {
463463
});
464464

465465
describe('test collector - complex scenarios', () => {
466-
it('should collect mix of tests, suites, hooks, and modifiers', () => {
467-
const collectedSuite = collectorFunctions.collectTests(() => {
466+
it('should collect mix of tests, suites, hooks, and modifiers', async () => {
467+
const collectedSuite = await collectorFunctions.collectTests(() => {
468468
collectorFunctions.describe('Complex Suite', () => {
469469
collectorFunctions.beforeAll(noop);
470470
collectorFunctions.beforeEach(noop);
@@ -515,14 +515,14 @@ describe('test collector - complex scenarios', () => {
515515
expect(innerSuite.tests[2].status).toBe('skipped'); // Due to .only
516516
});
517517

518-
it('should clear collector state between collectTests calls', () => {
519-
const collectedSuite1 = collectorFunctions.collectTests(() => {
518+
it('should clear collector state between collectTests calls', async () => {
519+
const collectedSuite1 = await collectorFunctions.collectTests(() => {
520520
collectorFunctions.describe('Suite 1', () => {
521521
collectorFunctions.it('test 1', noop);
522522
});
523523
});
524524

525-
const collectedSuite2 = collectorFunctions.collectTests(() => {
525+
const collectedSuite2 = await collectorFunctions.collectTests(() => {
526526
collectorFunctions.describe('Suite 2', () => {
527527
collectorFunctions.it('test 2', noop);
528528
});
@@ -534,8 +534,8 @@ describe('test collector - complex scenarios', () => {
534534
expect(collectedSuite2.testSuite.suites[0].name).toBe('Suite 2');
535535
});
536536

537-
it('should collect empty describe blocks', () => {
538-
const collectedSuite = collectorFunctions.collectTests(() => {
537+
it('should collect empty describe blocks', async () => {
538+
const collectedSuite = await collectorFunctions.collectTests(() => {
539539
collectorFunctions.describe('Empty Suite', () => {
540540
// No tests or hooks
541541
});

0 commit comments

Comments
 (0)