test_runner: print info when test restarts

When using spec reporter and running test in watch mode, print an info
message containing the current datetime when tests restart.

Fixes: https://github.com/nodejs/node/issues/57206
PR-URL: https://github.com/nodejs/node/pull/61160
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Xavier Stouder authored and GitHub committed 2026-01-17 17:33:57 +00:00
1 parent 8365edcbd0
commit a3ddfbe191
2 files changed
+23

No files matched your search

@@ -5,6 +5,8 @@ const {
ArrayPrototypePush,
ArrayPrototypeShift,
ArrayPrototypeUnshift,
Date,
DatePrototypeToLocaleString,
} = primordials;
const assert = require('assert');
const Transform = require('internal/streams/transform');
@@ -101,6 +103,9 @@ class SpecReporter extends Transform {
if (data.file === undefined) {
return this.#formatFailedTestResults();
}
break;
case 'test:watch:restarted':
return `\nRestarted at ${DatePrototypeToLocaleString(new Date())}\n`;
}
}
_transform({ type, data }, encoding, callback) {
@@ -0,0 +1,18 @@
import '../common/index.mjs';
import { spec as SpecReporter } from 'node:test/reporters';
import assert from 'node:assert';
const reporter = new SpecReporter();
let output = '';
reporter.on('data', (chunk) => {
output += chunk;
});
reporter.write({
type: 'test:watch:restarted',
});
reporter.end();
assert.match(output, /Restarted at .+/);