Skip to content

Commit a3b5473

Browse files
committed
test_runner: reset count on watch mode
1 parent b6f5a67 commit a3b5473

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/internal/test_runner/runner.js

+13-1
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
FunctionPrototypeCall,
1214
Number,
1315
ObjectAssign,
@@ -325,7 +327,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
325327
throw err;
326328
}
327329
});
328-
return subtest.start();
330+
const promise = subtest.start();
331+
if (filesWatcher) {
332+
return PromisePrototypeThen(promise, () => {
333+
const index = ArrayPrototypeIndexOf(root.subtests, subtest);
334+
if (index !== -1) {
335+
ArrayPrototypeSplice(root.subtests, index, 1);
336+
root.waitingOn--;
337+
}
338+
});
339+
}
340+
return promise;
329341
}
330342

331343
function watchFiles(testFiles, root, inspectPort) {
+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
require('./dependency.js');
22
import('./dependency.mjs');
33
import('data:text/javascript,');
4+
console.log('ok 1 - test has ran');

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ async function testWatch({ files, fileToUpdate }) {
1313
let stdout = '';
1414
child.stdout.on('data', (data) => {
1515
stdout += data.toString();
16-
if (/ok 2/.test(stdout)) ran1.resolve();
17-
if (/ok 3/.test(stdout)) ran2.resolve();
16+
const matches = stdout.match(/test has ran/g);
17+
if (matches?.length >= 1) ran1.resolve();
18+
if (matches?.length >= 2) ran2.resolve();
1819
});
1920

2021
await ran1.promise;
21-
writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8'));
22+
const interval = setInterval(() => writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')), 50);
2223
await ran2.promise;
24+
clearInterval(interval);
2325
child.kill();
2426
}
2527

2628
describe('test runner watch mode', () => {
2729
it('should run tests repeatedly', async () => {
2830
const file1 = fixtures.path('test-runner/index.test.js');
29-
const file2 = fixtures.path('test-runner/subdir/subdir_test.js');
31+
const file2 = fixtures.path('test-runner/dependent.js');
3032
await testWatch({ files: [file1, file2], fileToUpdate: file2 });
3133
});
3234

0 commit comments

Comments
 (0)