Skip to content

Commit 3bbb1fc

Browse files
committed
test_runner: fix test counting
PR-URL: #47675Fixes: #47365Fixes: #47696 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 64c3154 commit 3bbb1fc

8 files changed

Lines changed: 27 additions & 26 deletions

File tree

‎lib/internal/test_runner/harness.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function setup(root) {
174174
cancelled: 0,
175175
skipped: 0,
176176
todo: 0,
177-
planned: 0,
177+
topLevel: 0,
178178
suites: 0,
179179
},
180180
};

‎lib/internal/test_runner/runner.js‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ const {
55
ArrayPrototypeFilter,
66
ArrayPrototypeForEach,
77
ArrayPrototypeIncludes,
8-
ArrayPrototypeIndexOf,
98
ArrayPrototypeMap,
109
ArrayPrototypePush,
1110
ArrayPrototypeSlice,
1211
ArrayPrototypeSome,
1312
ArrayPrototypeSort,
14-
ArrayPrototypeSplice,
15-
Number,
1613
ObjectAssign,
1714
PromisePrototypeThen,
1815
SafePromiseAll,
@@ -206,7 +203,7 @@ class FileTest extends Test {
206203

207204
constdiagnostics=YAMLToJs(node.diagnostics);
208205
constcancelled=kCanceledTests.has(diagnostics.error?.failureType);
209-
consttestNumber=nesting===0 ? (Number(node.id)+this.testNumber-1) : node.id;
206+
consttestNumber=nesting===0 ? (this.root.harness.counters.topLevel+1) : node.id;
210207
constmethod=pass ? 'ok' : 'fail';
211208
this.reporter[method](nesting,this.name,testNumber,node.description,diagnostics,directive);
212209
if(nesting===0){
@@ -334,17 +331,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
334331
throwerr;
335332
}
336333
});
337-
constpromise=subtest.start();
338-
if(filesWatcher){
339-
returnPromisePrototypeThen(promise,()=>{
340-
constindex=ArrayPrototypeIndexOf(root.subtests,subtest);
341-
if(index!==-1){
342-
ArrayPrototypeSplice(root.subtests,index,1);
343-
root.waitingOn--;
344-
}
345-
});
346-
}
347-
returnpromise;
334+
returnsubtest.start();
348335
}
349336

350337
functionwatchFiles(testFiles,root,inspectPort,testNamePatterns){
@@ -360,6 +347,10 @@ function watchFiles(testFiles, root, inspectPort, testNamePatterns) {
360347
runningProcess.kill();
361348
awaitonce(runningProcess,'exit');
362349
}
350+
if(!runningSubtests.size){
351+
// Reset the topLevel counter
352+
root.harness.counters.topLevel=0;
353+
}
363354
awaitrunningSubtests.get(file);
364355
runningSubtests.set(file,runTestFile(file,root,inspectPort,filesWatcher,testNamePatterns));
365356
},undefined,(error)=>{

‎lib/internal/test_runner/test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ class Test extends AsyncResource {
637637
this.parent.processPendingSubtests();
638638
}elseif(!this.reported){
639639
this.reported=true;
640-
this.reporter.plan(this.nesting,kFilename,this.root.harness.counters.planned);
640+
this.reporter.plan(this.nesting,kFilename,this.root.harness.counters.topLevel);
641641

642642
for(leti=0;i<this.diagnostics.length;i++){
643643
this.reporter.diagnostic(this.nesting,kFilename,this.diagnostics[i]);

‎lib/internal/test_runner/utils.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function parseCommandLine() {
228228

229229
functioncountCompletedTest(test,harness=test.root.harness){
230230
if(test.nesting===0){
231-
harness.counters.planned++;
231+
harness.counters.topLevel++;
232232
}
233233
if(test.reportedType==='suite'){
234234
harness.counters.suites++;

‎test/fixtures/test-runner/output/output_cli.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const fixtures = require('../../../common/fixtures');
55
constspawn=require('node:child_process').spawn;
66

77
spawn(process.execPath,
8-
['--no-warnings','--test','--test-reporter','tap',fixtures.path('test-runner/output/output.js')],
8+
['--no-warnings','--test','--test-reporter','tap',fixtures.path('test-runner/output/output.js'),fixtures.path('test-runner/output/single.js')],
99
{stdio: 'inherit'});

‎test/fixtures/test-runner/output/output_cli.snapshot‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,15 @@ not ok 66 - invalid subtest fail
672672
# Warning: Test "immediate reject - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from immediate reject fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
673673
# Warning: Test "callback called twice in different ticks" generated asynchronous activity after the test ended. This activity created the error "Error [ERR_TEST_FAILURE]: callback invoked multiple times" and would have caused the test to fail, but instead triggered an uncaughtException event.
674674
# Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event.
675-
1..66
676-
# tests 80
675+
# Subtest: last test
676+
ok 67 - last test
677+
---
678+
duration_ms: *
679+
...
680+
1..67
681+
# tests 81
677682
# suites 0
678-
# pass 37
683+
# pass 38
679684
# fail 25
680685
# cancelled 3
681686
# skipped 10
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
consttest=require('node:test');
4+
test('last test',()=>{});

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ async function testWatch({ files, fileToUpdate }) {
1414

1515
child.stdout.on('data',(data)=>{
1616
stdout+=data.toString();
17-
constmatches=stdout.match(/testhasran/g);
18-
if(matches?.length>=1)ran1.resolve();
19-
if(matches?.length>=2)ran2.resolve();
17+
consttestRuns=stdout.match(/-testhasran/g);
18+
if(testRuns?.length>=1)ran1.resolve();
19+
if(testRuns?.length>=2)ran2.resolve();
2020
});
2121

2222
awaitran1.promise;
23-
constinterval=setInterval(()=>writeFileSync(fileToUpdate,readFileSync(fileToUpdate,'utf8')),50);
23+
constcontent=readFileSync(fileToUpdate,'utf8');
24+
constinterval=setInterval(()=>writeFileSync(fileToUpdate,content),10);
2425
awaitran2.promise;
2526
clearInterval(interval);
2627
child.kill();

0 commit comments

Comments
 (0)