Skip to content

Commit 71d8038

Browse files
test-runner: refactor to only emit test:watch:restarted event
1 parent e386f72 commit 71d8038

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

lib/internal/test_runner/reporter/dot.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ const {
44
MathMax,
55
} = primordials;
66
const colors = require('internal/util/colors');
7-
const {
8-
formatTestReport,
9-
reRunTestFileMessage
10-
} = require('internal/test_runner/reporter/utils');
7+
const { formatTestReport } = require('internal/test_runner/reporter/utils');
118

129
module.exports = async function* dot(source) {
1310
let count = 0;
@@ -28,9 +25,6 @@ module.exports = async function* dot(source) {
2825
columns = getLineLength();
2926
count = 0;
3027
}
31-
if(type === 'test:watch:restarted'){
32-
yield reRunTestFileMessage(data.file)
33-
}
3428
}
3529
yield '\n';
3630
if (failedTests.length > 0) {

lib/internal/test_runner/reporter/spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const {
1616
formatTestReport,
1717
indent,
1818
reporterColorMap,
19-
reporterUnicodeSymbolMap,
20-
reRunTestFileMessage
19+
reporterUnicodeSymbolMap
2120
} = require('internal/test_runner/reporter/utils');
2221

2322
class SpecReporter extends Transform {
@@ -100,8 +99,6 @@ class SpecReporter extends Transform {
10099
case 'test:coverage':
101100
return getCoverageReport(indent(data.nesting), data.summary,
102101
reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
103-
case 'test:watch:restarted':
104-
return reRunTestFileMessage(data.file)
105102
case 'test:summary':
106103
// We report only the root test summary
107104
if (data.file === undefined) {

lib/internal/test_runner/reporter/tap.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const {
1515
const { inspectWithNoCustomRetry } = require('internal/errors');
1616
const { isError, kEmptyObject } = require('internal/util');
1717
const { getCoverageReport } = require('internal/test_runner/utils');
18-
const { reRunTestFileMessage } = require('internal/test_runner/reporter/utils');
1918

2019
const kDefaultIndent = ' '; // 4 spaces
2120
const kFrameStartRegExp = /^ {4}at /;
@@ -63,9 +62,6 @@ async function * tapReporter(source) {
6362
case 'test:coverage':
6463
yield getCoverageReport(indent(data.nesting), data.summary, '# ', '', true);
6564
break;
66-
case 'test:watch:restarted':
67-
yield reRunTestFileMessage(data.file)
68-
break;
6965
}
7066
}
7167
}

lib/internal/test_runner/reporter/utils.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,10 @@ function formatTestReport(type, data, prefix = '', indent = '', hasChildren = fa
8484
return `${prefix}${indent}${color}${symbol}${title}${colors.white}${err}`;
8585
}
8686

87-
function reRunTestFileMessage(file) {
88-
return `\n[${new Date().toISOString()}] Restarting ${file}\n`
89-
}
90-
9187
module.exports = {
9288
__proto__: null,
9389
reporterUnicodeSymbolMap,
9490
reporterColorMap,
9591
formatTestReport,
9692
indent,
97-
reRunTestFileMessage
9893
};

lib/internal/test_runner/runner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ function watchFiles(testFiles, opts) {
480480
// Reset the topLevel counter
481481
opts.root.harness.counters.topLevel = 0;
482482
}
483-
opts.root.reporter[kEmitMessage]('test:watch:restarted', { file });
483+
484484
await runningSubtests.get(file);
485485
runningSubtests.set(file, runTestFile(file, filesWatcher, opts));
486486
}
@@ -508,6 +508,8 @@ function watchFiles(testFiles, opts) {
508508
// Reset the root start time to recalculate the duration
509509
// of the run
510510
opts.root.clearExecutionTime();
511+
opts.root.reporter[kEmitMessage]('test:watch:restarted');
512+
511513
// Restart test files
512514
if (opts.isolation === 'none') {
513515
PromisePrototypeThen(restartTestFile(kIsolatedProcessName), undefined, (error) => {

test/parallel/test-runner-run-watch.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,40 @@ describe('test runner watch mode', () => {
256256
});
257257
assert.notDeepStrictEqual(durations[0][1], durations[1][1]);
258258
});
259+
260+
it('should emits test:watch:restarted when file is updated', async () => {
261+
const testWatchRestarted = common.mustCall(1);
262+
263+
const controller = new AbortController();
264+
const stream = run({
265+
cwd: tmpdir.path,
266+
watch: true,
267+
signal: controller.signal,
268+
}).on('data', function({ type }) {
269+
if (type === 'test:watch:restarted') {
270+
testWatchRestarted();
271+
controller.abort();
272+
}
273+
})
274+
275+
writeFileSync(join(tmpdir.path, 'test.js'), fixtureContent['test.js']);
276+
277+
// eslint-disable-next-line no-unused-vars
278+
for await (const _ of stream);
279+
})
280+
281+
it('should not emit test:watch:restarted since watch mode is disabled', async () => {
282+
const stream = run({
283+
cwd: tmpdir.path,
284+
watch: false,
285+
})
286+
287+
stream.on('test:watch:restarted', common.mustNotCall())
288+
writeFileSync(join(tmpdir.path, 'test.js'), fixtureContent['test.js']);
289+
290+
// eslint-disable-next-line no-unused-vars
291+
for await (const _ of stream);
292+
})
259293

260294
describe('test runner watch mode with different cwd', () => {
261295
it(

0 commit comments

Comments
 (0)