Skip to content

Commit 30e493a

Browse files
authored
fix(jest-circus): always run beforeAll/afterAll in proper order with .concurrent tests in describe (#15825)
1 parent 1579380 commit 30e493a

File tree

13 files changed

+610
-128
lines changed

13 files changed

+610
-128
lines changed

e2e/__tests__/__snapshots__/circusConcurrent.test.ts.snap

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,36 @@ exports[`all passing runs the tests in the correct order 1`] = `
1616
1717
at log (__tests__/concurrent.test.js:15:11)
1818
19+
console.log
20+
START "eleven"
21+
22+
at log (__tests__/concurrent.test.js:15:11)
23+
24+
console.log
25+
START "twelve"
26+
27+
at log (__tests__/concurrent.test.js:15:11)
28+
29+
console.log
30+
END: "eleven"
31+
32+
at log (__tests__/concurrent.test.js:15:11)
33+
34+
console.log
35+
END: "twelve"
36+
37+
at log (__tests__/concurrent.test.js:15:11)
38+
39+
console.log
40+
END: "one"
41+
42+
at log (__tests__/concurrent.test.js:15:11)
43+
44+
console.log
45+
END: "two"
46+
47+
at log (__tests__/concurrent.test.js:15:11)
48+
1949
console.log
2050
START "three"
2151
@@ -27,57 +57,57 @@ exports[`all passing runs the tests in the correct order 1`] = `
2757
at log (__tests__/concurrent.test.js:15:11)
2858
2959
console.log
30-
START "five"
60+
START "nine"
3161
3262
at log (__tests__/concurrent.test.js:15:11)
3363
3464
console.log
35-
END: "three"
65+
START "ten"
3666
3767
at log (__tests__/concurrent.test.js:15:11)
3868
3969
console.log
40-
START "six"
70+
END: "three"
4171
4272
at log (__tests__/concurrent.test.js:15:11)
4373
4474
console.log
45-
END: "one"
75+
END: "nine"
4676
4777
at log (__tests__/concurrent.test.js:15:11)
4878
4979
console.log
50-
START "seven"
80+
END: "four"
5181
5282
at log (__tests__/concurrent.test.js:15:11)
5383
5484
console.log
55-
END: "two"
85+
END: "ten"
5686
5787
at log (__tests__/concurrent.test.js:15:11)
5888
5989
console.log
60-
START "eight"
90+
START hook "beforeAll level 2, group 1"
6191
6292
at log (__tests__/concurrent.test.js:15:11)
6393
6494
console.log
65-
END: "four"
95+
END hook: "beforeAll level 2, group 1"
6696
6797
at log (__tests__/concurrent.test.js:15:11)
6898
6999
console.log
70-
START "nine"
100+
START "five"
71101
72102
at log (__tests__/concurrent.test.js:15:11)
73103
74104
console.log
75-
END: "nine"
105+
START "six"
76106
77107
at log (__tests__/concurrent.test.js:15:11)
78108
79109
console.log
80-
START "ten"
110+
END: "six"
81111
82112
at log (__tests__/concurrent.test.js:15:11)
83113
@@ -87,17 +117,32 @@ exports[`all passing runs the tests in the correct order 1`] = `
87117
at log (__tests__/concurrent.test.js:15:11)
88118
89119
console.log
90-
END: "six"
120+
START hook "afterAll level 2, group 1"
91121
92122
at log (__tests__/concurrent.test.js:15:11)
93123
94124
console.log
95-
END: "seven"
125+
END hook: "afterAll level 2, group 1"
96126
97127
at log (__tests__/concurrent.test.js:15:11)
98128
99129
console.log
100-
END: "ten"
130+
START hook "beforeAll level 2, group 2"
131+
132+
at log (__tests__/concurrent.test.js:15:11)
133+
134+
console.log
135+
END hook: "beforeAll level 2, group 2"
136+
137+
at log (__tests__/concurrent.test.js:15:11)
138+
139+
console.log
140+
START "seven"
141+
142+
at log (__tests__/concurrent.test.js:15:11)
143+
144+
console.log
145+
START "eight"
101146
102147
at log (__tests__/concurrent.test.js:15:11)
103148
@@ -106,6 +151,21 @@ exports[`all passing runs the tests in the correct order 1`] = `
106151
107152
at log (__tests__/concurrent.test.js:15:11)
108153
154+
console.log
155+
END: "seven"
156+
157+
at log (__tests__/concurrent.test.js:15:11)
158+
159+
console.log
160+
START hook "afterAll level 2, group 2"
161+
162+
at log (__tests__/concurrent.test.js:15:11)
163+
164+
console.log
165+
END hook: "afterAll level 2, group 2"
166+
167+
at log (__tests__/concurrent.test.js:15:11)
168+
109169
console.log
110170
afterAll
111171
@@ -120,32 +180,32 @@ exports[`with only runs the tests in the correct order 1`] = `
120180
at log (__tests__/concurrent-only.test.js:15:11)
121181
122182
console.log
123-
START "four"
183+
START "nine"
124184
125185
at log (__tests__/concurrent-only.test.js:15:11)
126186
127187
console.log
128-
START "six"
188+
END: "nine"
129189
130190
at log (__tests__/concurrent-only.test.js:15:11)
131191
132192
console.log
133-
START "nine"
193+
START "four"
134194
135195
at log (__tests__/concurrent-only.test.js:15:11)
136196
137197
console.log
138-
END: "nine"
198+
END: "four"
139199
140200
at log (__tests__/concurrent-only.test.js:15:11)
141201
142202
console.log
143-
END: "six"
203+
START "six"
144204
145205
at log (__tests__/concurrent-only.test.js:15:11)
146206
147207
console.log
148-
END: "four"
208+
END: "six"
149209
150210
at log (__tests__/concurrent-only.test.js:15:11)
151211
@@ -173,52 +233,52 @@ exports[`with skip runs the tests in the correct order 1`] = `
173233
at log (__tests__/concurrent-skip.test.js:15:11)
174234
175235
console.log
176-
START "four"
236+
START "ten"
177237
178238
at log (__tests__/concurrent-skip.test.js:15:11)
179239
180240
console.log
181-
START "seven"
241+
END: "ten"
182242
183243
at log (__tests__/concurrent-skip.test.js:15:11)
184244
185245
console.log
186-
START "eight"
246+
END: "one"
187247
188248
at log (__tests__/concurrent-skip.test.js:15:11)
189249
190250
console.log
191-
END: "one"
251+
END: "two"
192252
193253
at log (__tests__/concurrent-skip.test.js:15:11)
194254
195255
console.log
196-
START "ten"
256+
START "four"
197257
198258
at log (__tests__/concurrent-skip.test.js:15:11)
199259
200260
console.log
201-
END: "two"
261+
START "seven"
202262
203263
at log (__tests__/concurrent-skip.test.js:15:11)
204264
205265
console.log
206-
END: "seven"
266+
START "eight"
207267
208268
at log (__tests__/concurrent-skip.test.js:15:11)
209269
210270
console.log
211-
END: "four"
271+
END: "seven"
212272
213273
at log (__tests__/concurrent-skip.test.js:15:11)
214274
215275
console.log
216-
END: "eight"
276+
END: "four"
217277
218278
at log (__tests__/concurrent-skip.test.js:15:11)
219279
220280
console.log
221-
END: "ten"
281+
END: "eight"
222282
223283
at log (__tests__/concurrent-skip.test.js:15:11)
224284

e2e/__tests__/__snapshots__/testRetries.test.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ exports[`Concurrent Test Retries with flag retryImmediately retry immediately af
3333
20 |
3434
3535
at Object.toBeFalsy (__tests__/retryImmediatelyConcurrent.test.js:17:18)
36-
at async Promise.all (index 0)
3736
3837
LOGGING RETRY ERRORS retryable test 2
3938
RETRY 1
@@ -67,7 +66,6 @@ exports[`Concurrent Test Retries with flag retryImmediately retry immediately af
6766
31 | it.concurrent('truthy test', () => {
6867
6968
at Object.toBeFalsy (__tests__/retryImmediatelyConcurrent.test.js:28:18)
70-
at async Promise.all (index 1)
7169
7270
PASS __tests__/retryImmediatelyConcurrent.test.js
7371
retryable test 1

e2e/__tests__/circusConcurrent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('all passing', () => {
1818
]);
1919

2020
expect(exitCode).toBe(0);
21-
expect(json.numTotalTests).toBe(10);
22-
expect(json.numPassedTests).toBe(10);
21+
expect(json.numTotalTests).toBe(12);
22+
expect(json.numPassedTests).toBe(12);
2323
expect(json.numFailedTests).toBe(0);
2424
expect(json.numPendingTests).toBe(0);
2525
});

e2e/__tests__/testRetries.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,11 @@ describe('Concurrent Test Retries', () => {
205205
SECOND TRUTHY TEST
206206
207207
at Object.log (__tests__/retryImmediatelyConcurrent.test.js:14:13)
208-
at async Promise.all (index 0)
209208
210209
console.log
211210
THIRD TRUTHY TEST
212211
213-
at Object.log (__tests__/retryImmediatelyConcurrent.test.js:25:13)
214-
at async Promise.all (index 1)`;
212+
at Object.log (__tests__/retryImmediatelyConcurrent.test.js:25:13)`;
215213

216214
const result = runJest('test-retries', [
217215
'retryImmediatelyConcurrent.test.js',

e2e/circus-concurrent/__tests__/concurrent.test.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ const testFn = (name, delay, fail) => {
3434
marker(`END: "${name}"`);
3535
};
3636
};
37+
const hookFn = (name, delay) => {
38+
return async () => {
39+
marker(`START hook "${name}"`);
40+
await setTimeout(delay);
41+
marker(`END hook: "${name}"`);
42+
};
43+
};
3744

3845
it.concurrent('one', testFn('one', 85));
3946
it.concurrent('two', testFn('two', 100));
@@ -43,21 +50,32 @@ describe('level 1', () => {
4350
afterEach(() => marker('afterEach level 1'));
4451

4552
it.concurrent('three', testFn('three', 70));
46-
4753
it.concurrent('four', testFn('four', 120));
4854

49-
describe('level 2', () => {
50-
beforeEach(() => marker('beforeEach level 2'));
51-
afterEach(() => marker('afterEach level 2'));
52-
it.concurrent('five', testFn('five', 160));
55+
describe('level 2, group 1', () => {
56+
beforeAll(hookFn('beforeAll level 2, group 1', 85));
57+
afterAll(hookFn('afterAll level 2, group 1', 85));
5358

59+
beforeEach(hookFn('beforeEach level 2, group 1', 85));
60+
afterEach(hookFn('afterEach level 2, group 1', 85));
61+
62+
it.concurrent('five', testFn('five', 160));
5463
it.concurrent('six', testFn('six', 100));
5564
});
65+
describe('level 2, group 2', () => {
66+
beforeAll(hookFn('beforeAll level 2, group 2', 85));
67+
afterAll(hookFn('afterAll level 2, group 2', 85));
5668

57-
it.concurrent('seven', testFn('seven', 100));
58-
it.concurrent('eight', testFn('eight', 120));
59-
});
69+
beforeEach(hookFn('beforeEach level 2, group 2', 85));
70+
afterEach(hookFn('afterEach level 2, group 2', 85));
6071

61-
it.concurrent('nine', testFn('nine', 20));
72+
it.concurrent('seven', testFn('seven', 160));
73+
it.concurrent('eight', testFn('eight', 100));
74+
});
75+
76+
it.concurrent('nine', testFn('nine', 100));
77+
it.concurrent('ten', testFn('ten', 120));
78+
});
6279

63-
it.concurrent('ten', testFn('ten', 50));
80+
it.concurrent('eleven', testFn('eleven', 20));
81+
it.concurrent('twelve', testFn('twelve', 50));

0 commit comments

Comments
 (0)