Skip to content

Commit 09db441

Browse files
committed
test_runner: reset count on watch mode
1 parent 85c8b78 commit 09db441

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/internal/test_runner/runner.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
296296
throw err;
297297
}
298298
});
299-
return subtest.start();
299+
const promise = subtest.start();
300+
if (filesWatcher) {
301+
return PromisePrototypeThen(promise, () => root.removeSubtest(subtest));
302+
}
303+
return promise;
300304
}
301305

302306
function watchFiles(testFiles, root, inspectPort) {

lib/internal/test_runner/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22
const {
3+
ArrayPrototypeIndexOf,
34
ArrayPrototypeMap,
45
ArrayPrototypePush,
56
ArrayPrototypeReduce,
67
ArrayPrototypeShift,
78
ArrayPrototypeSlice,
89
ArrayPrototypeSome,
10+
ArrayPrototypeSplice,
911
ArrayPrototypeUnshift,
1012
FunctionPrototype,
1113
MathMax,
@@ -344,6 +346,14 @@ class Test extends AsyncResource {
344346
}
345347
}
346348

349+
removeSubtest(subtest) {
350+
const index = ArrayPrototypeIndexOf(this.subtests, subtest);
351+
if (index !== -1) {
352+
ArrayPrototypeSplice(this.subtests, index, 1);
353+
this.waitingOn--;
354+
}
355+
}
356+
347357
createSubtest(Factory, name, options, fn, overrides) {
348358
if (typeof name === 'function') {
349359
fn = name;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ async function testWatch({ files, fileToUpdate }) {
1111
const ran2 = util.createDeferredPromise();
1212
const child = spawn(process.execPath, ['--watch', '--test', '--no-warnings', ...files], { encoding: 'utf8' });
1313
let stdout = '';
14+
let count = 0;
1415
child.stdout.on('data', (data) => {
1516
stdout += data.toString();
16-
if (/ok 2/.test(stdout)) ran1.resolve();
17-
if (/ok 3/.test(stdout)) ran2.resolve();
17+
if (/ok 1 - /.test(stdout)) {
18+
count++;
19+
}
20+
if (count === 2) ran1.resolve();
21+
if (count === 3) ran2.resolve();
1822
});
1923

2024
await ran1.promise;

0 commit comments

Comments
 (0)