Skip to content

Commit 17fbfb2

Browse files
MoLowdanielleadams
authored andcommitted
test_runner: reset count on watch mode
PR-URL: #46577 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7f9e60a commit 17fbfb2

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

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

330342
function watchFiles(testFiles, root, inspectPort) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const test = require('node:test');
12
require('./dependency.js');
23
import('./dependency.mjs');
34
import('data:text/javascript,');
5+
test('test has ran');

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ 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+
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+
const matches = stdout.match(/test has ran/g);
18+
if (matches?.length >= 1) ran1.resolve();
19+
if (matches?.length >= 2) ran2.resolve();
1820
});
1921

2022
await ran1.promise;
21-
writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8'));
23+
const interval = setInterval(() => writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')), 50);
2224
await ran2.promise;
25+
clearInterval(interval);
2326
child.kill();
2427
}
2528

2629
describe('test runner watch mode', () => {
2730
it('should run tests repeatedly', async () => {
2831
const file1 = fixtures.path('test-runner/index.test.js');
29-
const file2 = fixtures.path('test-runner/subdir/subdir_test.js');
32+
const file2 = fixtures.path('test-runner/dependent.js');
3033
await testWatch({ files: [file1, file2], fileToUpdate: file2 });
3134
});
3235

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy