Skip to content

Commit 6a0bd2f

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 8230688 commit 6a0bd2f

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
@@ -3435,6 +3435,9 @@ added:
34353435
- v18.9.0
34363436
- v16.19.0
34373437
changes:
3438+
- version: REPLACEME
3439+
pr-url: https://github.com/nodejs/node/pull/63435
3440+
description: Added `parentId` to test events that carry a `testId`.
34383441
- version:
34393442
- v20.0.0
34403443
- v19.9.0
@@ -3522,6 +3525,9 @@ Emitted when code coverage is enabled and all tests have completed.
35223525
`undefined` if the test was run through the REPL.
35233526
*`name` {string} The test name.
35243527
*`nesting` {number} The nesting level of the test.
3528+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3529+
`undefined` for top-level tests. Lets custom reporters track lineage
3530+
when concurrent siblings at the same nesting level interleave.
35253531
*`tags` {string\[]} The flattened lowercased tags declared on the test
35263532
and its ancestor suites, in declaration order. Empty for untagged tests.
35273533
See [Test tags][].
@@ -3548,6 +3554,9 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35483554
`undefined` if the test was run through the REPL.
35493555
*`name` {string} The test name.
35503556
*`nesting` {number} The nesting level of the test.
3557+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3558+
`undefined` for top-level tests. Lets custom reporters track lineage
3559+
when concurrent siblings at the same nesting level interleave.
35513560
*`tags` {string\[]} The flattened lowercased tags declared on the test
35523561
and its ancestor suites, in declaration order. Empty for untagged tests.
35533562
See [Test tags][].
@@ -3592,6 +3601,9 @@ defined.
35923601
`undefined` if the test was run through the REPL.
35933602
*`name` {string} The test name.
35943603
*`nesting` {number} The nesting level of the test.
3604+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3605+
`undefined` for top-level tests. Lets custom reporters track lineage
3606+
when concurrent siblings at the same nesting level interleave.
35953607
*`tags` {string\[]} The flattened lowercased tags declared on the test
35963608
and its ancestor suites, in declaration order. Empty for untagged tests.
35973609
See [Test tags][].
@@ -3621,6 +3633,9 @@ Emitted when a test is enqueued for execution.
36213633
`undefined` if the test was run through the REPL.
36223634
*`name` {string} The test name.
36233635
*`nesting` {number} The nesting level of the test.
3636+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3637+
`undefined` for top-level tests. Lets custom reporters track lineage
3638+
when concurrent siblings at the same nesting level interleave.
36243639
*`tags` {string\[]} The flattened lowercased tags declared on the test
36253640
and its ancestor suites, in declaration order. Empty for untagged tests.
36263641
See [Test tags][].
@@ -3681,6 +3696,9 @@ since the parent runner only knows about file-level tests. When using
36813696
`undefined` if the test was run through the REPL.
36823697
*`name` {string} The test name.
36833698
*`nesting` {number} The nesting level of the test.
3699+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3700+
`undefined` for top-level tests. Lets custom reporters track lineage
3701+
when concurrent siblings at the same nesting level interleave.
36843702
*`tags` {string\[]} The flattened lowercased tags declared on the test
36853703
and its ancestor suites, in declaration order. Empty for untagged tests.
36863704
See [Test tags][].
@@ -3723,6 +3741,9 @@ defined.
37233741
`undefined` if the test was run through the REPL.
37243742
*`name` {string} The test name.
37253743
*`nesting` {number} The nesting level of the test.
3744+
*`parentId` {number|undefined} The `testId` of the enclosing test, or
3745+
`undefined` for top-level tests. Lets custom reporters track lineage
3746+
when concurrent siblings at the same nesting level interleave.
37263747
*`tags` {string\[]} The flattened lowercased tags declared on the test
37273748
and its ancestor suites, in declaration order. Empty for untagged tests.
37283749
See [Test tags][].

‎lib/internal/test_runner/test.js‎

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

@@ -1235,7 +1236,8 @@ class Test extends AsyncResource {
12351236
}
12361237

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

@@ -1509,7 +1511,7 @@ class Test extends AsyncResource {
15091511
this.testNumber||=++this.parent.outputSubtestCount;
15101512
this.reporter.complete(
15111513
this.nesting,this.loc,this.testNumber,this.name,
1512-
report.details,report.directive,this.testId,this.tags,
1514+
report.details,report.directive,this.testId,this.parent?.testId,this.tags,
15131515
);
15141516
this.parent.activeSubtests--;
15151517
}
@@ -1665,12 +1667,12 @@ class Test extends AsyncResource {
16651667
if(this.passed){
16661668
this.reporter.ok(
16671669
this.nesting,this.loc,this.testNumber,this.name,
1668-
report.details,report.directive,this.testId,this.tags,
1670+
report.details,report.directive,this.testId,this.parent?.testId,this.tags,
16691671
);
16701672
}else{
16711673
this.reporter.fail(
16721674
this.nesting,this.loc,this.testNumber,this.name,
1673-
report.details,report.directive,this.testId,this.tags,
1675+
report.details,report.directive,this.testId,this.parent?.testId,this.tags,
16741676
);
16751677
}
16761678

@@ -1685,7 +1687,7 @@ class Test extends AsyncResource {
16851687
}
16861688
this.#reportedSubtest =true;
16871689
this.parent.reportStarted();
1688-
this.reporter.start(this.nesting,this.loc,this.name,this.testId,this.tags);
1690+
this.reporter.start(this.nesting,this.loc,this.name,this.testId,this.parent?.testId,this.tags);
16891691
}
16901692

16911693
clearExecutionTime(){
@@ -1747,7 +1749,7 @@ class TestHook extends Test {
17471749
__proto__: null,
17481750
duration_ms: this.duration(),
17491751
error,
1750-
},undefined,undefined,parent.tags);
1752+
},undefined,undefined,undefined,parent.tags);
17511753
}
17521754
}
17531755
}

‎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)