Skip to content

Commit a3ddfbe

Browse files
authored
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: #57206 PR-URL: #61160 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 8365edc commit a3ddfbe

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/internal/test_runner/reporter/spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const {
55
ArrayPrototypePush,
66
ArrayPrototypeShift,
77
ArrayPrototypeUnshift,
8+
Date,
9+
DatePrototypeToLocaleString,
810
} = primordials;
911
const assert = require('assert');
1012
const Transform = require('internal/streams/transform');
@@ -101,6 +103,9 @@ class SpecReporter extends Transform {
101103
if (data.file === undefined) {
102104
return this.#formatFailedTestResults();
103105
}
106+
break;
107+
case 'test:watch:restarted':
108+
return `\nRestarted at ${DatePrototypeToLocaleString(new Date())}\n`;
104109
}
105110
}
106111
_transform({ type, data }, encoding, callback) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import '../common/index.mjs';
2+
import { spec as SpecReporter } from 'node:test/reporters';
3+
import assert from 'node:assert';
4+
5+
const reporter = new SpecReporter();
6+
let output = '';
7+
8+
reporter.on('data', (chunk) => {
9+
output += chunk;
10+
});
11+
12+
reporter.write({
13+
type: 'test:watch:restarted',
14+
});
15+
16+
reporter.end();
17+
18+
assert.match(output, /Restarted at .+/);

0 commit comments

Comments
 (0)