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 de4f14c

Browse filesBrowse files
MoLowRafaelGSS
authored andcommitted
test_runner: add enqueue and dequeue events
PR-URL: #48428 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 5cacdf9 commit de4f14c
Copy full SHA for de4f14c

File tree

Expand file treeCollapse file tree

4 files changed

+39
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+39
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/test.md‎

Copy file name to clipboardExpand all lines: doc/api/test.md
+23-1Lines changed: 23 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,16 @@ object, streaming a series of events representing the execution of the tests.
14591459

14601460
Emitted when code coverage is enabled and all tests have completed.
14611461

1462+
### Event: `'test:dequeue'`
1463+
1464+
* `data` {Object}
1465+
* `file` {string|undefined} The path of the test file,
1466+
undefined if test is not ran through a file.
1467+
* `name` {string} The test name.
1468+
* `nesting` {number} The nesting level of the test.
1469+
1470+
Emitted when a test is dequeued, right before it is executed.
1471+
14621472
### Event: `'test:diagnostic'`
14631473

14641474
* `data` {Object}
@@ -1469,6 +1479,16 @@ Emitted when code coverage is enabled and all tests have completed.
14691479

14701480
Emitted when [`context.diagnostic`][] is called.
14711481

1482+
### Event: `'test:enqueue'`
1483+
1484+
* `data` {Object}
1485+
* `file` {string|undefined} The path of the test file,
1486+
undefined if test is not ran through a file.
1487+
* `name` {string} The test name.
1488+
* `nesting` {number} The nesting level of the test.
1489+
1490+
Emitted when a test is enqueued for execution.
1491+
14721492
### Event: `'test:fail'`
14731493

14741494
* `data` {Object}
@@ -1518,7 +1538,9 @@ Emitted when all subtests have completed for a given test.
15181538
* `name` {string} The test name.
15191539
* `nesting` {number} The nesting level of the test.
15201540

1521-
Emitted when a test starts.
1541+
Emitted when a test starts reporting its own and its subtests status.
1542+
This event is guaranteed to be emitted in the same order as the tests are
1543+
defined.
15221544

15231545
### Event: `'test:stderr'`
15241546

Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ class Test extends AsyncResource {
311311
async processPendingSubtests() {
312312
while (this.pendingSubtests.length > 0 && this.hasConcurrency()) {
313313
const deferred = ArrayPrototypeShift(this.pendingSubtests);
314-
await deferred.test.run();
314+
const test = deferred.test;
315+
this.reporter.dequeue(test.nesting, kFilename, test.name);
316+
await test.run();
315317
deferred.resolve();
316318
}
317319
}
@@ -469,6 +471,7 @@ class Test extends AsyncResource {
469471
// If there is enough available concurrency to run the test now, then do
470472
// it. Otherwise, return a Promise to the caller and mark the test as
471473
// pending for later execution.
474+
this.reporter.enqueue(this.nesting, kFilename, this.name);
472475
if (!this.parent.hasConcurrency()) {
473476
const deferred = createDeferredPromise();
474477

@@ -477,6 +480,7 @@ class Test extends AsyncResource {
477480
return deferred.promise;
478481
}
479482

483+
this.reporter.dequeue(this.nesting, kFilename, this.name);
480484
return this.run();
481485
}
482486

Collapse file

‎lib/internal/test_runner/tests_stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/tests_stream.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class TestsStream extends Readable {
4949
return { __proto__: null, todo: reason ?? true };
5050
}
5151

52+
enqueue(nesting, file, name) {
53+
this[kEmitMessage]('test:enqueue', { __proto__: null, nesting, file, name });
54+
}
55+
56+
dequeue(nesting, file, name) {
57+
this[kEmitMessage]('test:dequeue', { __proto__: null, nesting, file, name });
58+
}
59+
5260
start(nesting, file, name) {
5361
this[kEmitMessage]('test:start', { __proto__: null, nesting, file, name });
5462
}
Collapse file

‎test/parallel/test-runner-reporters.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-reporters.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('node:test reporters', { concurrency: true }, () => {
9797
testFile]);
9898
assert.strictEqual(child.stderr.toString(), '');
9999
const stdout = child.stdout.toString();
100-
assert.match(stdout, /{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/);
100+
assert.match(stdout, /{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/);
101101
assert.strictEqual(stdout.slice(0, filename.length + 2), `${filename} {`);
102102
});
103103
});
@@ -109,7 +109,7 @@ describe('node:test reporters', { concurrency: true }, () => {
109109
assert.strictEqual(child.stderr.toString(), '');
110110
assert.match(
111111
child.stdout.toString(),
112-
/^package: reporter-cjs{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/,
112+
/^package: reporter-cjs{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/,
113113
);
114114
});
115115

@@ -120,7 +120,7 @@ describe('node:test reporters', { concurrency: true }, () => {
120120
assert.strictEqual(child.stderr.toString(), '');
121121
assert.match(
122122
child.stdout.toString(),
123-
/^package: reporter-esm{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/,
123+
/^package: reporter-esm{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/,
124124
);
125125
});
126126

0 commit comments

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