Skip to content

Commit 659d5bf

Browse files
MoLowaduh95
authored andcommitted
test_runner: add parentId to test events with testId
Signed-off-by: Moshe Atlow <moshe@atlow.co.il> PR-URL: #63435 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 2922290 commit 659d5bf

3 files changed

Lines changed: 43 additions & 14 deletions

File tree

‎doc/api/test.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,9 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/63435
3435+
description: Added `parentId` to test events that carry a `testId`.
34333436
- version:
34343437
- v20.0.0
34353438
- v19.9.0
@@ -3517,6 +3520,9 @@ Emitted when code coverage is enabled and all tests have completed.
35173520
`undefined` if the test was run through the REPL.
35183521
*`name` {string} The test name.
35193522
*`nesting` {number} The nesting level of the test.
3523+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3524+
`undefined` for top-level tests. Lets custom reporters track lineage
3525+
when concurrent siblings at the same nesting level interleave.
35203526
*`tags` {string\[]} The flattened lowercased tags declared on the test
35213527
and its ancestor suites, in declaration order. Empty for untagged tests.
35223528
See [Test tags][].
@@ -3543,6 +3549,9 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433549
`undefined` if the test was run through the REPL.
35443550
*`name` {string} The test name.
35453551
*`nesting` {number} The nesting level of the test.
3552+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3553+
`undefined` for top-level tests. Lets custom reporters track lineage
3554+
when concurrent siblings at the same nesting level interleave.
35463555
*`tags` {string\[]} The flattened lowercased tags declared on the test
35473556
and its ancestor suites, in declaration order. Empty for untagged tests.
35483557
See [Test tags][].
@@ -3587,6 +3596,9 @@ defined.
35873596
`undefined` if the test was run through the REPL.
35883597
*`name` {string} The test name.
35893598
*`nesting` {number} The nesting level of the test.
3599+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3600+
`undefined` for top-level tests. Lets custom reporters track lineage
3601+
when concurrent siblings at the same nesting level interleave.
35903602
*`tags` {string\[]} The flattened lowercased tags declared on the test
35913603
and its ancestor suites, in declaration order. Empty for untagged tests.
35923604
See [Test tags][].
@@ -3616,6 +3628,9 @@ Emitted when a test is enqueued for execution.
36163628
`undefined` if the test was run through the REPL.
36173629
*`name` {string} The test name.
36183630
*`nesting` {number} The nesting level of the test.
3631+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3632+
`undefined` for top-level tests. Lets custom reporters track lineage
3633+
when concurrent siblings at the same nesting level interleave.
36193634
*`tags` {string\[]} The flattened lowercased tags declared on the test
36203635
and its ancestor suites, in declaration order. Empty for untagged tests.
36213636
See [Test tags][].
@@ -3676,6 +3691,9 @@ since the parent runner only knows about file-level tests. When using
36763691
`undefined` if the test was run through the REPL.
36773692
*`name` {string} The test name.
36783693
*`nesting` {number} The nesting level of the test.
3694+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3695+
`undefined` for top-level tests. Lets custom reporters track lineage
3696+
when concurrent siblings at the same nesting level interleave.
36793697
*`tags` {string\[]} The flattened lowercased tags declared on the test
36803698
and its ancestor suites, in declaration order. Empty for untagged tests.
36813699
See [Test tags][].
@@ -3718,6 +3736,9 @@ defined.
37183736
`undefined` if the test was run through the REPL.
37193737
*`name` {string} The test name.
37203738
*`nesting` {number} The nesting level of the test.
3739+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3740+
`undefined` for top-level tests. Lets custom reporters track lineage
3741+
when concurrent siblings at the same nesting level interleave.
37213742
*`tags` {string\[]} The flattened lowercased tags declared on the test
37223743
and its ancestor suites, in declaration order. Empty for untagged tests.
37233744
See [Test tags][].

‎lib/internal/test_runner/test.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ class Test extends AsyncResource {
956956
constdeferred=this.dequeuePendingSubtest();
957957
consttest=deferred.test;
958958
this.assignReportOrder(test);
959-
test.reporter.dequeue(test.nesting,test.loc,test.name,this.reportedType,test.testId,test.tags);
959+
test.reporter.dequeue(test.nesting,test.loc,test.name,this.reportedType,test.testId,this.testId,test.tags);
960960
awaittest.run();
961961
deferred.resolve();
962962
}
@@ -1213,7 +1213,8 @@ class Test extends AsyncResource {
12131213
// it. Otherwise, return a Promise to the caller and mark the test as
12141214
// pending for later execution.
12151215
this.parent.unfinishedSubtests.add(this);
1216-
this.reporter.enqueue(this.nesting,this.loc,this.name,this.reportedType,this.testId,this.tags);
1216+
this.reporter.enqueue(this.nesting,this.loc,this.name,this.reportedType,
1217+
this.testId,this.parent?.testId,this.tags);
12171218
if(this.root.harness.buildPromise||!this.parent.hasConcurrency()){
12181219
constdeferred=PromiseWithResolvers();
12191220

@@ -1236,7 +1237,8 @@ class Test extends AsyncResource {
12361237
}
12371238

12381239
this.parent.assignReportOrder(this);
1239-
this.reporter.dequeue(this.nesting,this.loc,this.name,this.reportedType,this.testId,this.tags);
1240+
this.reporter.dequeue(this.nesting,this.loc,this.name,this.reportedType,
1241+
this.testId,this.parent?.testId,this.tags);
12401242
returnthis.run();
12411243
}
12421244

@@ -1510,7 +1512,7 @@ class Test extends AsyncResource {
15101512
this.testNumber||=++this.parent.outputSubtestCount;
15111513
this.reporter.complete(
15121514
this.nesting,this.loc,this.testNumber,this.name,
1513-
report.details,report.directive,this.testId,this.tags,
1515+
report.details,report.directive,this.testId,this.parent?.testId,this.tags,
15141516
);
15151517
this.parent.activeSubtests--;
15161518
}
@@ -1666,12 +1668,12 @@ class Test extends AsyncResource {
16661668
if(this.passed){
16671669
this.reporter.ok(
16681670
this.nesting,this.loc,this.testNumber,this.name,
1669-
report.details,report.directive,this.testId,this.tags,
1671+
report.details,report.directive,this.testId,this.parent?.testId,this.tags,
16701672
);
16711673
}else{
16721674
this.reporter.fail(
16731675
this.nesting,this.loc,this.testNumber,this.name,
1674-
report.details,report.directive,this.testId,this.tags,
1676+
report.details,report.directive,this.testId,this.parent?.testId,this.tags,
16751677
);
16761678
}
16771679

@@ -1686,7 +1688,7 @@ class Test extends AsyncResource {
16861688
}
16871689
this.#reportedSubtest =true;
16881690
this.parent.reportStarted();
1689-
this.reporter.start(this.nesting,this.loc,this.name,this.testId,this.tags);
1691+
this.reporter.start(this.nesting,this.loc,this.name,this.testId,this.parent?.testId,this.tags);
16901692
}
16911693

16921694
clearExecutionTime(){
@@ -1748,7 +1750,7 @@ class TestHook extends Test {
17481750
__proto__: null,
17491751
duration_ms: this.duration(),
17501752
error,
1751-
},undefined,undefined,parent.tags);
1753+
},undefined,undefined,undefined,parent.tags);
17521754
}
17531755
}
17541756
}

‎lib/internal/test_runner/tests_stream.js‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,44 @@ class TestsStream extends Readable {
3535
}
3636
}
3737

38-
fail(nesting,loc,testNumber,name,details,directive,testId,tags){
38+
fail(nesting,loc,testNumber,name,details,directive,testId,parentId,tags){
3939
this[kEmitMessage]('test:fail',{
4040
__proto__: null,
4141
name,
4242
nesting,
4343
testNumber,
4444
testId,
45+
parentId,
4546
details,
4647
tags: ArrayPrototypeSlice(tags),
4748
...loc,
4849
...directive,
4950
});
5051
}
5152

52-
ok(nesting,loc,testNumber,name,details,directive,testId,tags){
53+
ok(nesting,loc,testNumber,name,details,directive,testId,parentId,tags){
5354
this[kEmitMessage]('test:pass',{
5455
__proto__: null,
5556
name,
5657
nesting,
5758
testNumber,
5859
testId,
60+
parentId,
5961
details,
6062
tags: ArrayPrototypeSlice(tags),
6163
...loc,
6264
...directive,
6365
});
6466
}
6567

66-
complete(nesting,loc,testNumber,name,details,directive,testId,tags){
68+
complete(nesting,loc,testNumber,name,details,directive,testId,parentId,tags){
6769
this[kEmitMessage]('test:complete',{
6870
__proto__: null,
6971
name,
7072
nesting,
7173
testNumber,
7274
testId,
75+
parentId,
7376
details,
7477
tags: ArrayPrototypeSlice(tags),
7578
...loc,
@@ -98,36 +101,39 @@ class TestsStream extends Readable {
98101
return{__proto__: null,expectFailure: expectation??true};
99102
}
100103

101-
enqueue(nesting,loc,name,type,testId,tags){
104+
enqueue(nesting,loc,name,type,testId,parentId,tags){
102105
this[kEmitMessage]('test:enqueue',{
103106
__proto__: null,
104107
nesting,
105108
name,
106109
type,
107110
testId,
111+
parentId,
108112
tags: ArrayPrototypeSlice(tags),
109113
...loc,
110114
});
111115
}
112116

113-
dequeue(nesting,loc,name,type,testId,tags){
117+
dequeue(nesting,loc,name,type,testId,parentId,tags){
114118
this[kEmitMessage]('test:dequeue',{
115119
__proto__: null,
116120
nesting,
117121
name,
118122
type,
119123
testId,
124+
parentId,
120125
tags: ArrayPrototypeSlice(tags),
121126
...loc,
122127
});
123128
}
124129

125-
start(nesting,loc,name,testId,tags){
130+
start(nesting,loc,name,testId,parentId,tags){
126131
this[kEmitMessage]('test:start',{
127132
__proto__: null,
128133
nesting,
129134
name,
130135
testId,
136+
parentId,
131137
tags: ArrayPrototypeSlice(tags),
132138
...loc,
133139
});

0 commit comments

Comments
 (0)