Skip to content

Commit e919512

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

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

lib/internal/test_runner/runner.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ const {
44
ArrayPrototypeFilter,
55
ArrayPrototypeForEach,
66
ArrayPrototypeIncludes,
7+
ArrayPrototypeIndexOf,
78
ArrayPrototypePush,
89
ArrayPrototypeSlice,
910
ArrayPrototypeSome,
1011
ArrayPrototypeSort,
12+
ArrayPrototypeSplice,
1113
ObjectAssign,
1214
PromisePrototypeThen,
1315
SafePromiseAll,
@@ -296,7 +298,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
296298
throw err;
297299
}
298300
});
299-
return subtest.start();
301+
const promise = subtest.start();
302+
if (filesWatcher) {
303+
return PromisePrototypeThen(promise, () => {
304+
const index = ArrayPrototypeIndexOf(root.subtests, subtest);
305+
if (index !== -1) {
306+
ArrayPrototypeSplice(root.subtests, index, 1);
307+
root.waitingOn--;
308+
}
309+
});
310+
}
311+
return promise;
300312
}
301313

302314
function watchFiles(testFiles, root, inspectPort) {

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)