Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c02aa0

Browse filesBrowse files
MoLowaduh95
authored andcommitted
test_runner: fix suite rerun
PR-URL: #61775 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
1 parent 26a09e5 commit 1c02aa0
Copy full SHA for 1c02aa0

3 files changed

+42-12Lines changed: 42 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,12 @@ class Test extends AsyncResource {
706706
this.fn = () => {
707707
for (let i = 0; i < (previousAttempt.children?.length ?? 0); i++) {
708708
const child = previousAttempt.children[i];
709-
this.createSubtest(Test, child.name, { __proto__: null }, noop, {
709+
const t = this.createSubtest(Test, child.name, { __proto__: null }, noop, {
710710
__proto__: null,
711711
loc: [child.line, child.column, child.file],
712-
}, noop).start();
712+
}, noop);
713+
t.endTime = t.startTime = hrtime();
714+
t.start();
713715
}
714716
};
715717
}
Collapse file

‎test/fixtures/test-runner/rerun.js‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/rerun.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { test } = require('node:test')
1+
const { test, describe } = require('node:test')
22

33
test('should fail on first two attempts', ({ attempt }) => {
44
if (attempt < 2) {
@@ -38,3 +38,11 @@ function nestedAmbiguousTest(expectedAttempts) {
3838

3939
test('nested ambiguous (expectedAttempts=0)', nestedAmbiguousTest(0));
4040
test('nested ambiguous (expectedAttempts=1)', nestedAmbiguousTest(2));
41+
42+
43+
describe('describe rerun', { timeout: 1000, concurrency: 1000 }, () => {
44+
test('passed on first attempt', async (t) => {
45+
await t.test('nested', async () => {});
46+
});
47+
test('a');
48+
});
Collapse file

‎test/parallel/test-runner-test-rerun-failures.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-test-rerun-failures.js
+29-9Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const expectedStateFile = [
2323
'test/fixtures/test-runner/rerun.js:39:1': { passed_on_attempt: 0, name: 'nested ambiguous (expectedAttempts=0)' },
2424
'test/fixtures/test-runner/rerun.js:30:16:(1)': { passed_on_attempt: 0, name: '2 levels deep' },
2525
'test/fixtures/test-runner/rerun.js:35:13:(1)': { passed_on_attempt: 0, name: 'ok' },
26+
'test/fixtures/test-runner/rerun.js:45:13': { passed_on_attempt: 0, name: 'nested' },
27+
'test/fixtures/test-runner/rerun.js:44:3': { passed_on_attempt: 0, name: 'passed on first attempt' },
28+
'test/fixtures/test-runner/rerun.js:47:3': { passed_on_attempt: 0, name: 'a' },
29+
'test/fixtures/test-runner/rerun.js:43:1': { passed_on_attempt: 0, name: 'describe rerun' },
2630
},
2731
{
2832
'test/fixtures/test-runner/rerun.js:9:1': { passed_on_attempt: 0, name: 'ok' },
@@ -34,6 +38,11 @@ const expectedStateFile = [
3438
'test/fixtures/test-runner/rerun.js:39:1': { passed_on_attempt: 0, name: 'nested ambiguous (expectedAttempts=0)' },
3539
'test/fixtures/test-runner/rerun.js:30:16:(1)': { passed_on_attempt: 0, name: '2 levels deep' },
3640
'test/fixtures/test-runner/rerun.js:35:13:(1)': { passed_on_attempt: 0, name: 'ok' },
41+
'test/fixtures/test-runner/rerun.js:43:1': { passed_on_attempt: 0, name: 'describe rerun' },
42+
'test/fixtures/test-runner/rerun.js:44:3': { passed_on_attempt: 0, name: 'passed on first attempt' },
43+
'test/fixtures/test-runner/rerun.js:45:13': { passed_on_attempt: 0, name: 'nested' },
44+
'test/fixtures/test-runner/rerun.js:45:13:(1)': { passed_on_attempt: 1, name: 'nested' },
45+
'test/fixtures/test-runner/rerun.js:47:3': { passed_on_attempt: 0, name: 'a' },
3746
},
3847
{
3948
'test/fixtures/test-runner/rerun.js:3:1': { passed_on_attempt: 2, name: 'should fail on first two attempts' },
@@ -48,6 +57,11 @@ const expectedStateFile = [
4857
'test/fixtures/test-runner/rerun.js:30:16:(1)': { passed_on_attempt: 0, name: '2 levels deep' },
4958
'test/fixtures/test-runner/rerun.js:35:13:(1)': { passed_on_attempt: 0, name: 'ok' },
5059
'test/fixtures/test-runner/rerun.js:40:1': { passed_on_attempt: 2, name: 'nested ambiguous (expectedAttempts=1)' },
60+
'test/fixtures/test-runner/rerun.js:43:1': { passed_on_attempt: 0, name: 'describe rerun' },
61+
'test/fixtures/test-runner/rerun.js:44:3': { passed_on_attempt: 0, name: 'passed on first attempt' },
62+
'test/fixtures/test-runner/rerun.js:45:13': { passed_on_attempt: 0, name: 'nested' },
63+
'test/fixtures/test-runner/rerun.js:45:13:(1)': { passed_on_attempt: 1, name: 'nested' },
64+
'test/fixtures/test-runner/rerun.js:47:3': { passed_on_attempt: 0, name: 'a' },
5165
},
5266
];
5367

@@ -67,23 +81,26 @@ test('test should pass on third rerun', async () => {
6781
let { code, stdout, signal } = await common.spawnPromisified(process.execPath, args);
6882
assert.strictEqual(code, 1);
6983
assert.strictEqual(signal, null);
70-
assert.match(stdout, /pass 8/);
84+
assert.match(stdout, /pass 11/);
7185
assert.match(stdout, /fail 4/);
86+
assert.match(stdout, /suites 1/);
7287
assert.deepStrictEqual(await getStateFile(), expectedStateFile.slice(0, 1));
7388

7489
({ code, stdout, signal } = await common.spawnPromisified(process.execPath, args));
7590
assert.strictEqual(code, 1);
7691
assert.strictEqual(signal, null);
77-
assert.match(stdout, /pass 9/);
92+
assert.match(stdout, /pass 13/);
7893
assert.match(stdout, /fail 3/);
94+
assert.match(stdout, /suites 1/);
7995
assert.deepStrictEqual(await getStateFile(), expectedStateFile.slice(0, 2));
8096

8197

8298
({ code, stdout, signal } = await common.spawnPromisified(process.execPath, args));
8399
assert.strictEqual(code, 0);
84100
assert.strictEqual(signal, null);
85-
assert.match(stdout, /pass 12/);
101+
assert.match(stdout, /pass 18/);
86102
assert.match(stdout, /fail 0/);
103+
assert.match(stdout, /suites 1/);
87104
assert.deepStrictEqual(await getStateFile(), expectedStateFile);
88105
});
89106

@@ -93,29 +110,32 @@ test('test should pass on third rerun with `--test`', async () => {
93110
let { code, stdout, signal } = await common.spawnPromisified(process.execPath, args);
94111
assert.strictEqual(code, 1);
95112
assert.strictEqual(signal, null);
96-
assert.match(stdout, /pass 8/);
113+
assert.match(stdout, /pass 11/);
97114
assert.match(stdout, /fail 4/);
115+
assert.match(stdout, /suites 1/);
98116
assert.deepStrictEqual(await getStateFile(), expectedStateFile.slice(0, 1));
99117

100118
({ code, stdout, signal } = await common.spawnPromisified(process.execPath, args));
101119
assert.strictEqual(code, 1);
102120
assert.strictEqual(signal, null);
103-
assert.match(stdout, /pass 9/);
121+
assert.match(stdout, /pass 13/);
104122
assert.match(stdout, /fail 3/);
123+
assert.match(stdout, /suites 1/);
105124
assert.deepStrictEqual(await getStateFile(), expectedStateFile.slice(0, 2));
106125

107126

108127
({ code, stdout, signal } = await common.spawnPromisified(process.execPath, args));
109128
assert.strictEqual(code, 0);
110129
assert.strictEqual(signal, null);
111-
assert.match(stdout, /pass 12/);
130+
assert.match(stdout, /pass 18/);
112131
assert.match(stdout, /fail 0/);
132+
assert.match(stdout, /suites 1/);
113133
assert.deepStrictEqual(await getStateFile(), expectedStateFile);
114134
});
115135

116136
test('using `run` api', async () => {
117137
let stream = run({ files: [fixture], rerunFailuresFilePath: stateFile });
118-
stream.on('test:pass', common.mustCall(8));
138+
stream.on('test:pass', common.mustCall(12));
119139
stream.on('test:fail', common.mustCall(4));
120140

121141
// eslint-disable-next-line no-unused-vars
@@ -125,7 +145,7 @@ test('using `run` api', async () => {
125145

126146

127147
stream = run({ files: [fixture], rerunFailuresFilePath: stateFile });
128-
stream.on('test:pass', common.mustCall(9));
148+
stream.on('test:pass', common.mustCall(14));
129149
stream.on('test:fail', common.mustCall(3));
130150

131151
// eslint-disable-next-line no-unused-vars
@@ -135,7 +155,7 @@ test('using `run` api', async () => {
135155

136156

137157
stream = run({ files: [fixture], rerunFailuresFilePath: stateFile });
138-
stream.on('test:pass', common.mustCall(12));
158+
stream.on('test:pass', common.mustCall(19));
139159
stream.on('test:fail', common.mustNotCall());
140160

141161
// eslint-disable-next-line no-unused-vars

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.