Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3bbb1fc

Browse filesBrowse files
committed
test_runner: fix test counting
PR-URL: #47675 Fixes: #47365 Fixes: #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
Copy full SHA for 3bbb1fc

File tree

Expand file treeCollapse file tree

8 files changed

+27
-26
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+27
-26
lines changed
Open diff view settings
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+1-1Lines 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
};
Collapse file

‎lib/internal/test_runner/runner.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js
+6-15Lines 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
const diagnostics = YAMLToJs(node.diagnostics);
208205
const cancelled = kCanceledTests.has(diagnostics.error?.failureType);
209-
const testNumber = nesting === 0 ? (Number(node.id) + this.testNumber - 1) : node.id;
206+
const testNumber = nesting === 0 ? (this.root.harness.counters.topLevel + 1) : node.id;
210207
const method = 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
throw err;
335332
}
336333
});
337-
const promise = subtest.start();
338-
if (filesWatcher) {
339-
return PromisePrototypeThen(promise, () => {
340-
const index = ArrayPrototypeIndexOf(root.subtests, subtest);
341-
if (index !== -1) {
342-
ArrayPrototypeSplice(root.subtests, index, 1);
343-
root.waitingOn--;
344-
}
345-
});
346-
}
347-
return promise;
334+
return subtest.start();
348335
}
349336

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

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+1-1Lines 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
} else if (!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 (let i = 0; i < this.diagnostics.length; i++) {
643643
this.reporter.diagnostic(this.nesting, kFilename, this.diagnostics[i]);
Collapse file

‎lib/internal/test_runner/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/utils.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function parseCommandLine() {
228228

229229
function countCompletedTest(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++;
Collapse file

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

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/output_cli.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const fixtures = require('../../../common/fixtures');
55
const spawn = 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' });
Collapse file

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

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/output_cli.snapshot
+8-3Lines 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
Collapse file
+4Lines 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+
const test = require('node:test');
4+
test('last test', () => {});
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-runner-watch-mode.mjs
+5-4Lines 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-
const matches = stdout.match(/test has ran/g);
18-
if (matches?.length >= 1) ran1.resolve();
19-
if (matches?.length >= 2) ran2.resolve();
17+
const testRuns = stdout.match(/ - test has ran/g);
18+
if (testRuns?.length >= 1) ran1.resolve();
19+
if (testRuns?.length >= 2) ran2.resolve();
2020
});
2121

2222
await ran1.promise;
23-
const interval = setInterval(() => writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')), 50);
23+
const content = readFileSync(fileToUpdate, 'utf8');
24+
const interval = setInterval(() => writeFileSync(fileToUpdate, content), 10);
2425
await ran2.promise;
2526
clearInterval(interval);
2627
child.kill();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.