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 8, 2023
1 parent 85c8b78 commit 09db441
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
throw err;
}
});
return subtest.start();
const promise = subtest.start();
if (filesWatcher) {
return PromisePrototypeThen(promise, () => root.removeSubtest(subtest));
}
return promise;
}

function watchFiles(testFiles, root, inspectPort) {
Expand Down
10 changes: 10 additions & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';
const {
ArrayPrototypeIndexOf,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeReduce,
ArrayPrototypeShift,
ArrayPrototypeSlice,
ArrayPrototypeSome,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
FunctionPrototype,
MathMax,
Expand Down Expand Up @@ -344,6 +346,14 @@ class Test extends AsyncResource {
}
}

removeSubtest(subtest) {
const index = ArrayPrototypeIndexOf(this.subtests, subtest);
if (index !== -1) {
ArrayPrototypeSplice(this.subtests, index, 1);
this.waitingOn--;
}
}

createSubtest(Factory, name, options, fn, overrides) {
if (typeof name === 'function') {
fn = name;
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 09db441

Please sign in to comment.