forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrerun.js
More file actions
67 lines (55 loc) · 2.08 KB
/
rerun.js
File metadata and controls
67 lines (55 loc) · 2.08 KB
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
58
59
60
61
62
63
64
65
66
67
const { test, describe } = require('node:test')
test('should fail on first two attempts', ({ attempt }) => {
if (attempt < 2) {
throw new Error('This test is expected to fail on the first two attempts');
}
});
test('ok', ({ attempt }) => {
if (attempt > 0) {
throw new Error('Test should not rerun once it has passed');
}
});
function ambiguousTest(expectedAttempts) {
test(`ambiguous (expectedAttempts=${expectedAttempts})`, ({ attempt }) => {
if (attempt < expectedAttempts) {
throw new Error(`This test is expected to fail on the first ${expectedAttempts} attempts`);
}
});
}
ambiguousTest(0);
ambiguousTest(1);
function nestedAmbiguousTest(expectedAttempts) {
return async (t) => {
await t.test('nested', async (tt) => {
await tt.test('2 levels deep', () => {});
if (t.attempt < expectedAttempts) {
throw new Error(`This test is expected to fail on the first ${expectedAttempts} attempts`);
}
});
await t.test('ok', () => {});
};
}
test('nested ambiguous (expectedAttempts=0)', nestedAmbiguousTest(0));
test('nested ambiguous (expectedAttempts=1)', nestedAmbiguousTest(2));
describe('describe rerun', { timeout: 1000, concurrency: 1000 }, () => {
test('passed on first attempt', async (t) => {
await t.test('nested', async () => {});
});
test('a');
});
// Shared helper creates subtests at the same source location each time it's
// called, producing ambiguous test identifiers (disambiguated with ":(N)"
// suffixes in the rerun state file). Regression coverage for a bug where the
// suite's synthetic rerun fn double-started its direct children, which then
// re-invoked the synthetic descendant-creator against an already-incremented
// disambiguator map and emitted spurious failures.
function ambiguousHelper(t) {
return Promise.all([
t.test('shared sub A', () => {}),
t.test('shared sub B', () => {}),
]);
}
describe('rerun with ambiguous shared helper', { timeout: 1000, concurrency: 1000 }, () => {
test('first caller', (t) => ambiguousHelper(t));
test('second caller', (t) => ambiguousHelper(t));
});