test_runner: Better visibility when using `--test-rerun` by MoLow · Pull Request #63429 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/test_runner/reporter/rerun.js
5 changes: 4 additions & 1 deletion lib/internal/test_runner/reporter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ function formatTestReport(type, data, showErrorDetails = true, prefix = '', inde
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
const { skip, todo, expectFailure } = data;
const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
let title = `${data.name}${duration_ms}`;
const replayed = data.details?.passed_on_attempt !== undefined ?
` ${colors.gray}(passed on attempt ${data.details.passed_on_attempt})${colors.white}` :
'';
let title = `${data.name}${duration_ms}${replayed}`;

if (skip !== undefined) {
title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
Expand Down
15 changes: 14 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const {
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
ArrayPrototypeUnshiftApply,
BigInt,
Error,
FunctionPrototype,
MathFloor,
MathMax,
MathRound,
Number,
NumberPrototypeToFixed,
ObjectFreeze,
Expand Down Expand Up @@ -803,14 +805,25 @@ class Test extends AsyncResource {
const previousAttempt = this.root.harness.previousRuns[this.attempt - 1]?.[testIdentifier];
if (previousAttempt != null) {
this.passedAttempt = previousAttempt.passed_on_attempt;
if (previousAttempt.duration_ms !== undefined) {
this.replayedDurationNs = BigInt(MathRound(previousAttempt.duration_ms * 1_000_000));
}
this.fn = () => {
// Restore the original duration on the synthetic replay. Suites are
// skipped here because Suite.run() unconditionally reassigns
// startTime later; only non-suite tests benefit from setting it.
if (this.reportedType !== 'suite') {
this.startTime = hrtime();
this.endTime = this.startTime + (this.replayedDurationNs ?? 0n);
}
for (let i = 0; i < (previousAttempt.children?.length ?? 0); i++) {
const child = previousAttempt.children[i];
const t = this.createSubtest(Test, child.name, { __proto__: null }, noop, {
__proto__: null,
loc: [child.line, child.column, child.file],
}, noop);
t.endTime = t.startTime = hrtime();
t.startTime = hrtime();
t.endTime = t.startTime + (t.replayedDurationNs ?? 0n);
// For suites, Suite.run() starts the subtests via SafePromiseAll.
// Starting them here as well would run them twice, re-invoking the
// synthetic children-creator against a now-incremented disambiguator
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/test-runner/rerun-duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
// A passing test with a measurable duration alongside a failing test. The
// failing test forces the rerun feature to retry on a second invocation,
// causing the passing test to be replayed via the synthetic noop stub.
const { test } = require('node:test');

test('passing slow test', async () => {
await new Promise((resolve) => setTimeout(resolve, 25));
});

test('always failing', () => {
throw new Error('boom');
});
22 changes: 22 additions & 0 deletions test/parallel/test-runner-test-rerun-failures.js
Loading