Skip to content

Commit

Permalink
test_runner: reset count on watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Feb 18, 2023
1 parent 4ba860e commit 8e1d279
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypeIncludes,
ArrayPrototypeIndexOf,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSome,
ArrayPrototypeSort,
ArrayPrototypeSplice,
FunctionPrototypeCall,
Number,
ObjectAssign,
Expand Down Expand Up @@ -319,7 +321,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
throw err;
}
});
return subtest.start();
const promise = subtest.start();
if (filesWatcher) {
return PromisePrototypeThen(promise, () => {
const index = ArrayPrototypeIndexOf(root.subtests, subtest);
if (index !== -1) {
ArrayPrototypeSplice(root.subtests, index, 1);
root.waitingOn--;
}
});
}
return promise;
}

function watchFiles(testFiles, root, inspectPort) {
Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-runner-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ async function testWatch({ files, fileToUpdate }) {
const ran2 = util.createDeferredPromise();
const child = spawn(process.execPath, ['--watch', '--test', '--no-warnings', ...files], { encoding: 'utf8' });
let stdout = '';
let count = 0;
child.stdout.on('data', (data) => {
stdout += data.toString();
if (/ok 2/.test(stdout)) ran1.resolve();
if (/ok 3/.test(stdout)) ran2.resolve();
if (/ok 1 - /.test(stdout)) {
count++;
}
if (count === 2) ran1.resolve();
if (count === 3) ran2.resolve();
});

await ran1.promise;
Expand Down

0 comments on commit 8e1d279

Please sign in to comment.