-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.ts
57 lines (48 loc) · 1.01 KB
/
hooks.ts
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
const order: unknown[] = [];
const failuresLeft = [1, 2, 0];
const B = 'B';
const b = 'b';
const a = 'a';
const A = 'A';
jest.retryTimes(2);
describe('Hooks', () => {
beforeAll(() => {
order.push(B);
});
beforeEach(() => {
order.push(b);
});
test.each([[1], [2], [3]])('test %i', (i) => {
const fails = failuresLeft[i - 1];
if (fails > 0) {
order.push(-i);
failuresLeft[i - 1] = fails - 1;
throw new Error(`Flaky${i}`);
} else {
order.push(i);
}
});
afterEach(() => {
order.push(a);
});
afterAll(() => {
order.push(A);
});
});
afterAll(() => {
if (countOf(1) === 1 && countOf(2) === 1 && countOf(3) === 1) {
/* eslint-disable prettier/prettier */
expect(order).toEqual([
B, b, -1, a, A,
B, b, -2, a, A,
B, b, 3, a,
b, 1, a,
b, -2, a, A,
B, b, 2, a, A,
]);
/* eslint-enable prettier/prettier */
}
});
function countOf(value: unknown) {
return order.filter((v) => v === value).length;
}