Skip to content

Commit 839a06e

Browse files
EddieAbbondanzioRafaelGSS
authored andcommitted
test_runner: differentiate test types in enqueue dequeue events
PR-URL: #54049 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Pietro Marchini <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 3aca628 commit 839a06e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+517
-5
lines changed

doc/api/test.md

+2
Original file line numberDiff line numberDiff line change
@@ -2951,6 +2951,7 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
29512951
`undefined` if the test was run through the REPL.
29522952
* `name` {string} The test name.
29532953
* `nesting` {number} The nesting level of the test.
2954+
* `type` {string} The test type. Either `'suite'` or `'test'`.
29542955

29552956
Emitted when a test is dequeued, right before it is executed.
29562957
This event is not guaranteed to be emitted in the same order as the tests are
@@ -2983,6 +2984,7 @@ defined.
29832984
`undefined` if the test was run through the REPL.
29842985
* `name` {string} The test name.
29852986
* `nesting` {number} The nesting level of the test.
2987+
* `type` {string} The test type. Either `'suite'` or `'test'`.
29862988

29872989
Emitted when a test is enqueued for execution.
29882990

lib/internal/test_runner/test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class SuiteContext {
363363
}
364364

365365
class Test extends AsyncResource {
366+
reportedType = 'test';
366367
abortController;
367368
outerSignal;
368369
#reportedSubtest;
@@ -609,7 +610,7 @@ class Test extends AsyncResource {
609610
while (this.pendingSubtests.length > 0 && this.hasConcurrency()) {
610611
const deferred = ArrayPrototypeShift(this.pendingSubtests);
611612
const test = deferred.test;
612-
test.reporter.dequeue(test.nesting, test.loc, test.name);
613+
test.reporter.dequeue(test.nesting, test.loc, test.name, this.reportedType);
613614
await test.run();
614615
deferred.resolve();
615616
}
@@ -800,7 +801,7 @@ class Test extends AsyncResource {
800801
// If there is enough available concurrency to run the test now, then do
801802
// it. Otherwise, return a Promise to the caller and mark the test as
802803
// pending for later execution.
803-
this.reporter.enqueue(this.nesting, this.loc, this.name);
804+
this.reporter.enqueue(this.nesting, this.loc, this.name, this.reportedType);
804805
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
805806
const deferred = PromiseWithResolvers();
806807

@@ -809,7 +810,7 @@ class Test extends AsyncResource {
809810
return deferred.promise;
810811
}
811812

812-
this.reporter.dequeue(this.nesting, this.loc, this.name);
813+
this.reporter.dequeue(this.nesting, this.loc, this.name, this.reportedType);
813814
return this.run();
814815
}
815816

@@ -1179,6 +1180,7 @@ class Test extends AsyncResource {
11791180
}
11801181

11811182
class TestHook extends Test {
1183+
reportedType = 'hook';
11821184
#args;
11831185
constructor(fn, options) {
11841186
const { hookType, loc, parent, timeout, signal } = options;

lib/internal/test_runner/tests_stream.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,22 @@ class TestsStream extends Readable {
8787
return { __proto__: null, todo: reason ?? true };
8888
}
8989

90-
enqueue(nesting, loc, name) {
90+
enqueue(nesting, loc, name, type) {
9191
this[kEmitMessage]('test:enqueue', {
9292
__proto__: null,
9393
nesting,
9494
name,
95+
type,
9596
...loc,
9697
});
9798
}
9899

99-
dequeue(nesting, loc, name) {
100+
dequeue(nesting, loc, name, type) {
100101
this[kEmitMessage]('test:dequeue', {
101102
__proto__: null,
102103
nesting,
103104
name,
105+
type,
104106
...loc,
105107
});
106108
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const {test, suite} = require('node:test');
3+
4+
suite('this is a suite');
5+
test('this is a test');

test/fixtures/test-runner/output/abort-runs-after-hook.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ AFTER
44
not ok 1 - test that aborts
55
---
66
duration_ms: *
7+
type: 'test'
78
location: '/test/fixtures/test-runner/output/abort-runs-after-hook.js:(LINE):1'
89
failureType: 'uncaughtException'
910
error: 'boom'

test/fixtures/test-runner/output/abort.snapshot

+22
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ TAP version 13
44
ok 1 - ok 1
55
---
66
duration_ms: *
7+
type: 'test'
78
...
89
# Subtest: ok 2
910
ok 2 - ok 2
1011
---
1112
duration_ms: *
13+
type: 'test'
1214
...
1315
# Subtest: ok 3
1416
ok 3 - ok 3
1517
---
1618
duration_ms: *
19+
type: 'test'
1720
...
1821
# Subtest: ok 4
1922
ok 4 - ok 4
2023
---
2124
duration_ms: *
25+
type: 'test'
2226
...
2327
# Subtest: not ok 1
2428
not ok 5 - not ok 1
2529
---
2630
duration_ms: *
31+
type: 'test'
2732
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
2833
failureType: 'cancelledByParent'
2934
error: 'test did not finish before its parent and was cancelled'
@@ -33,6 +38,7 @@ TAP version 13
3338
not ok 6 - not ok 2
3439
---
3540
duration_ms: *
41+
type: 'test'
3642
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
3743
failureType: 'cancelledByParent'
3844
error: 'test did not finish before its parent and was cancelled'
@@ -42,6 +48,7 @@ TAP version 13
4248
not ok 7 - not ok 3
4349
---
4450
duration_ms: *
51+
type: 'test'
4552
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
4653
failureType: 'testAborted'
4754
error: 'This operation was aborted'
@@ -63,6 +70,7 @@ TAP version 13
6370
not ok 8 - not ok 4
6471
---
6572
duration_ms: *
73+
type: 'test'
6674
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
6775
failureType: 'testAborted'
6876
error: 'This operation was aborted'
@@ -84,6 +92,7 @@ TAP version 13
8492
not ok 9 - not ok 5
8593
---
8694
duration_ms: *
95+
type: 'test'
8796
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
8897
failureType: 'testAborted'
8998
error: 'This operation was aborted'
@@ -105,6 +114,7 @@ TAP version 13
105114
not ok 1 - promise timeout signal
106115
---
107116
duration_ms: *
117+
type: 'test'
108118
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
109119
failureType: 'testAborted'
110120
error: 'The operation was aborted due to timeout'
@@ -120,6 +130,7 @@ not ok 1 - promise timeout signal
120130
not ok 2 - promise abort signal
121131
---
122132
duration_ms: *
133+
type: 'test'
123134
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
124135
failureType: 'testAborted'
125136
error: 'This operation was aborted'
@@ -142,26 +153,31 @@ not ok 2 - promise abort signal
142153
ok 1 - ok 1
143154
---
144155
duration_ms: *
156+
type: 'test'
145157
...
146158
# Subtest: ok 2
147159
ok 2 - ok 2
148160
---
149161
duration_ms: *
162+
type: 'test'
150163
...
151164
# Subtest: ok 3
152165
ok 3 - ok 3
153166
---
154167
duration_ms: *
168+
type: 'test'
155169
...
156170
# Subtest: ok 4
157171
ok 4 - ok 4
158172
---
159173
duration_ms: *
174+
type: 'test'
160175
...
161176
# Subtest: not ok 1
162177
not ok 5 - not ok 1
163178
---
164179
duration_ms: *
180+
type: 'test'
165181
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
166182
failureType: 'cancelledByParent'
167183
error: 'test did not finish before its parent and was cancelled'
@@ -171,6 +187,7 @@ not ok 2 - promise abort signal
171187
not ok 6 - not ok 2
172188
---
173189
duration_ms: *
190+
type: 'test'
174191
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
175192
failureType: 'cancelledByParent'
176193
error: 'test did not finish before its parent and was cancelled'
@@ -180,6 +197,7 @@ not ok 2 - promise abort signal
180197
not ok 7 - not ok 3
181198
---
182199
duration_ms: *
200+
type: 'test'
183201
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
184202
failureType: 'testAborted'
185203
error: 'This operation was aborted'
@@ -201,6 +219,7 @@ not ok 2 - promise abort signal
201219
not ok 8 - not ok 4
202220
---
203221
duration_ms: *
222+
type: 'test'
204223
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
205224
failureType: 'testAborted'
206225
error: 'This operation was aborted'
@@ -222,6 +241,7 @@ not ok 2 - promise abort signal
222241
not ok 9 - not ok 5
223242
---
224243
duration_ms: *
244+
type: 'test'
225245
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
226246
failureType: 'testAborted'
227247
error: 'This operation was aborted'
@@ -243,6 +263,7 @@ not ok 2 - promise abort signal
243263
not ok 3 - callback timeout signal
244264
---
245265
duration_ms: *
266+
type: 'test'
246267
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
247268
failureType: 'testAborted'
248269
error: 'The operation was aborted due to timeout'
@@ -258,6 +279,7 @@ not ok 3 - callback timeout signal
258279
not ok 4 - callback abort signal
259280
---
260281
duration_ms: *
282+
type: 'test'
261283
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
262284
failureType: 'testAborted'
263285
error: 'This operation was aborted'

test/fixtures/test-runner/output/abort_hooks.snapshot

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ TAP version 13
1212
not ok 1 - test 1
1313
---
1414
duration_ms: *
15+
type: 'test'
1516
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
1617
failureType: 'cancelledByParent'
1718
error: 'test did not finish before its parent and was cancelled'
@@ -21,6 +22,7 @@ TAP version 13
2122
not ok 2 - test 2
2223
---
2324
duration_ms: *
25+
type: 'test'
2426
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
2527
failureType: 'cancelledByParent'
2628
error: 'test did not finish before its parent and was cancelled'
@@ -53,11 +55,13 @@ not ok 1 - 1 before describe
5355
ok 1 - test 1
5456
---
5557
duration_ms: *
58+
type: 'test'
5659
...
5760
# Subtest: test 2
5861
ok 2 - test 2
5962
---
6063
duration_ms: *
64+
type: 'test'
6165
...
6266
1..2
6367
not ok 2 - 2 after describe
@@ -86,6 +90,7 @@ not ok 2 - 2 after describe
8690
not ok 1 - test 1
8791
---
8892
duration_ms: *
93+
type: 'test'
8994
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
9095
failureType: 'hookFailed'
9196
error: 'This operation was aborted'
@@ -107,6 +112,7 @@ not ok 2 - 2 after describe
107112
not ok 2 - test 2
108113
---
109114
duration_ms: *
115+
type: 'test'
110116
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
111117
failureType: 'hookFailed'
112118
error: 'This operation was aborted'
@@ -139,6 +145,7 @@ not ok 3 - 3 beforeEach describe
139145
not ok 1 - test 1
140146
---
141147
duration_ms: *
148+
type: 'test'
142149
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
143150
failureType: 'hookFailed'
144151
error: 'This operation was aborted'
@@ -160,6 +167,7 @@ not ok 3 - 3 beforeEach describe
160167
not ok 2 - test 2
161168
---
162169
duration_ms: *
170+
type: 'test'
163171
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
164172
failureType: 'hookFailed'
165173
error: 'This operation was aborted'

test/fixtures/test-runner/output/abort_suite.snapshot

+9
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ TAP version 13
44
ok 1 - ok 1
55
---
66
duration_ms: *
7+
type: 'test'
78
...
89
# Subtest: ok 2
910
ok 2 - ok 2
1011
---
1112
duration_ms: *
13+
type: 'test'
1214
...
1315
# Subtest: ok 3
1416
ok 3 - ok 3
1517
---
1618
duration_ms: *
19+
type: 'test'
1720
...
1821
# Subtest: ok 4
1922
ok 4 - ok 4
2023
---
2124
duration_ms: *
25+
type: 'test'
2226
...
2327
# Subtest: not ok 1
2428
not ok 5 - not ok 1
2529
---
2630
duration_ms: *
31+
type: 'test'
2732
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
2833
failureType: 'cancelledByParent'
2934
error: 'test did not finish before its parent and was cancelled'
@@ -33,6 +38,7 @@ TAP version 13
3338
not ok 6 - not ok 2
3439
---
3540
duration_ms: *
41+
type: 'test'
3642
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
3743
failureType: 'cancelledByParent'
3844
error: 'test did not finish before its parent and was cancelled'
@@ -42,6 +48,7 @@ TAP version 13
4248
not ok 7 - not ok 3
4349
---
4450
duration_ms: *
51+
type: 'test'
4552
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
4653
failureType: 'testAborted'
4754
error: 'This operation was aborted'
@@ -63,6 +70,7 @@ TAP version 13
6370
not ok 8 - not ok 4
6471
---
6572
duration_ms: *
73+
type: 'test'
6674
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
6775
failureType: 'testAborted'
6876
error: 'This operation was aborted'
@@ -84,6 +92,7 @@ TAP version 13
8492
not ok 9 - not ok 5
8593
---
8694
duration_ms: *
95+
type: 'test'
8796
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
8897
failureType: 'testAborted'
8998
error: 'This operation was aborted'

test/fixtures/test-runner/output/arbitrary-output-colored.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ TAP version 13
1616
ok 1 - passing test
1717
---
1818
duration_ms: *
19+
type: 'test'
1920
...
2021
1..1
2122
# tests 1

0 commit comments

Comments
 (0)