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

3 files changed

Lines changed: 22 additions & 5 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
FunctionPrototypeCall,
1214
Number,
1315
ObjectAssign,
@@ -324,7 +326,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
324326
throwerr;
325327
}
326328
});
327-
returnsubtest.start();
329+
constpromise=subtest.start();
330+
if(filesWatcher){
331+
returnPromisePrototypeThen(promise,()=>{
332+
constindex=ArrayPrototypeIndexOf(root.subtests,subtest);
333+
if(index!==-1){
334+
ArrayPrototypeSplice(root.subtests,index,1);
335+
root.waitingOn--;
336+
}
337+
});
338+
}
339+
returnpromise;
328340
}
329341

330342
functionwatchFiles(testFiles,root,inspectPort){
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
consttest=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
constran2=util.createDeferredPromise();
1212
constchild=spawn(process.execPath,['--watch','--test','--no-warnings', ...files],{encoding: 'utf8'});
1313
letstdout='';
14+
1415
child.stdout.on('data',(data)=>{
1516
stdout+=data.toString();
16-
if(/ok2/.test(stdout))ran1.resolve();
17-
if(/ok3/.test(stdout))ran2.resolve();
17+
constmatches=stdout.match(/testhasran/g);
18+
if(matches?.length>=1)ran1.resolve();
19+
if(matches?.length>=2)ran2.resolve();
1820
});
1921

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

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

0 commit comments

Comments
 (0)