Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit add1edb

Browse files
MoLowaduh95
authored andcommitted
test_runner: report entryFile in TestStream events
Signed-off-by: Moshe Atlov <moshe@atlow.co.il> PR-URL: #64309 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 949bc3c commit add1edb

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ added:
34303430
- v18.9.0
34313431
- v16.19.0
34323432
changes:
3433+
- version: REPLACEME
3434+
pr-url: https://github.com/nodejs/node/pull/64309
3435+
description: Added `entryFile` to events forwarded from child processes
3436+
when tests run with process isolation.
34333437
- version: v24.19.0
34343438
pr-url: https://github.com/nodejs/node/pull/63435
34353439
description: Added `parentId` to test events that carry a `testId`.
@@ -3514,6 +3518,10 @@ Emitted when code coverage is enabled and all tests have completed.
35143518
*`cause` {Error} The actual error thrown by the test.
35153519
*`type` {string|undefined} The type of the test, used to denote whether
35163520
this is a suite.
3521+
*`entryFile` {string|undefined} The path of the test file that was
3522+
executed as the entry point of the child process that emitted this event.
3523+
Only present when tests run with process isolation. May differ from
3524+
`file` when the test is defined in a module imported by the entry file.
35173525
*`file` {string|undefined} The path of the test file,
35183526
`undefined` if test was run through the REPL.
35193527
*`line` {number|undefined} The line number where the test is defined, or
@@ -3543,6 +3551,10 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
35433551
*`data` {Object}
35443552
*`column` {number|undefined} The column number where the test is defined, or
35453553
`undefined` if the test was run through the REPL.
3554+
*`entryFile` {string|undefined} The path of the test file that was
3555+
executed as the entry point of the child process that emitted this event.
3556+
Only present when tests run with process isolation. May differ from
3557+
`file` when the test is defined in a module imported by the entry file.
35463558
*`file` {string|undefined} The path of the test file,
35473559
`undefined` if test was run through the REPL.
35483560
*`line` {number|undefined} The line number where the test is defined, or
@@ -3569,6 +3581,10 @@ defined. The corresponding declaration ordered event is `'test:start'`.
35693581
*`data` {Object}
35703582
*`column` {number|undefined} The column number where the test is defined, or
35713583
`undefined` if the test was run through the REPL.
3584+
*`entryFile` {string|undefined} The path of the test file that was
3585+
executed as the entry point of the child process that emitted this event.
3586+
Only present when tests run with process isolation. May differ from
3587+
`file` when the test is defined in a module imported by the entry file.
35723588
*`file` {string|undefined} The path of the test file,
35733589
`undefined` if test was run through the REPL.
35743590
*`line` {number|undefined} The line number where the test is defined, or
@@ -3590,6 +3606,10 @@ defined.
35903606
*`data` {Object}
35913607
*`column` {number|undefined} The column number where the test is defined, or
35923608
`undefined` if the test was run through the REPL.
3609+
*`entryFile` {string|undefined} The path of the test file that was
3610+
executed as the entry point of the child process that emitted this event.
3611+
Only present when tests run with process isolation. May differ from
3612+
`file` when the test is defined in a module imported by the entry file.
35933613
*`file` {string|undefined} The path of the test file,
35943614
`undefined` if test was run through the REPL.
35953615
*`line` {number|undefined} The line number where the test is defined, or
@@ -3622,6 +3642,10 @@ Emitted when a test is enqueued for execution.
36223642
this is a suite.
36233643
*`attempt` {number|undefined} The attempt number of the test run,
36243644
present only when using the [`--test-rerun-failures`][] flag.
3645+
*`entryFile` {string|undefined} The path of the test file that was
3646+
executed as the entry point of the child process that emitted this event.
3647+
Only present when tests run with process isolation. May differ from
3648+
`file` when the test is defined in a module imported by the entry file.
36253649
*`file` {string|undefined} The path of the test file,
36263650
`undefined` if test was run through the REPL.
36273651
*`line` {number|undefined} The line number where the test is defined, or
@@ -3685,6 +3709,10 @@ since the parent runner only knows about file-level tests. When using
36853709
present only when using the [`--test-rerun-failures`][] flag.
36863710
*`passed_on_attempt` {number|undefined} The attempt number the test passed on,
36873711
present only when using the [`--test-rerun-failures`][] flag.
3712+
*`entryFile` {string|undefined} The path of the test file that was
3713+
executed as the entry point of the child process that emitted this event.
3714+
Only present when tests run with process isolation. May differ from
3715+
`file` when the test is defined in a module imported by the entry file.
36883716
*`file` {string|undefined} The path of the test file,
36893717
`undefined` if test was run through the REPL.
36903718
*`line` {number|undefined} The line number where the test is defined, or
@@ -3714,6 +3742,10 @@ The corresponding execution ordered event is `'test:complete'`.
37143742
*`data` {Object}
37153743
*`column` {number|undefined} The column number where the test is defined, or
37163744
`undefined` if the test was run through the REPL.
3745+
*`entryFile` {string|undefined} The path of the test file that was
3746+
executed as the entry point of the child process that emitted this event.
3747+
Only present when tests run with process isolation. May differ from
3748+
`file` when the test is defined in a module imported by the entry file.
37173749
*`file` {string|undefined} The path of the test file,
37183750
`undefined` if test was run through the REPL.
37193751
*`line` {number|undefined} The line number where the test is defined, or
@@ -3730,6 +3762,10 @@ defined.
37303762
*`data` {Object}
37313763
*`column` {number|undefined} The column number where the test is defined, or
37323764
`undefined` if the test was run through the REPL.
3765+
*`entryFile` {string|undefined} The path of the test file that was
3766+
executed as the entry point of the child process that emitted this event.
3767+
Only present when tests run with process isolation. May differ from
3768+
`file` when the test is defined in a module imported by the entry file.
37333769
*`file` {string|undefined} The path of the test file,
37343770
`undefined` if test was run through the REPL.
37353771
*`line` {number|undefined} The line number where the test is defined, or
@@ -3754,6 +3790,9 @@ The corresponding execution ordered event is `'test:dequeue'`.
37543790
### Event: `'test:stderr'`
37553791

37563792
*`data` {Object}
3793+
*`entryFile` {string|undefined} The path of the test file that was
3794+
executed as the entry point of the child process that emitted this event.
3795+
Only present when tests run with process isolation.
37573796
*`file` {string} The path of the test file.
37583797
*`message` {string} The message written to `stderr`.
37593798

@@ -3765,6 +3804,9 @@ defined.
37653804
### Event: `'test:stdout'`
37663805

37673806
*`data` {Object}
3807+
*`entryFile` {string|undefined} The path of the test file that was
3808+
executed as the entry point of the child process that emitted this event.
3809+
Only present when tests run with process isolation.
37683810
*`file` {string} The path of the test file.
37693811
*`message` {string} The message written to `stdout`.
37703812

β€Žlib/internal/test_runner/runner.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class FileTest extends Test {
295295
ArrayPrototypeIncludes(kDiagnosticsFilterArgs,StringPrototypeSlice(comment,0,firstSpaceIndex));
296296
}
297297
#handleReportItem(item){
298+
// The name is empty when a single child process runs all test files.
299+
if(this.name!==''){
300+
item.data.entryFile=this.loc.file;
301+
}
298302
constisTopLevel=item.data.nesting===0;
299303
if(isTopLevel){
300304
if(item.type==='test:plan'&&this.#skipReporting()){
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup A',async(t)=>{awaitrunShared(t,'A');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import{test}from'node:test';
2+
import{runShared}from'./helper.mjs';
3+
test('backup B',async(t)=>{awaitrunShared(t,'B');});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportasyncfunctionrunShared(t,target){
2+
awaitt.test(`restore ${target}`,async()=>{});
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import'../common/index.mjs';
2+
import*asfixturesfrom'../common/fixtures.mjs';
3+
import{describe,it,run}from'node:test';
4+
importassertfrom'node:assert';
5+
6+
constaPath=fixtures.path('test-runner','entry-file','a.test.mjs');
7+
constbPath=fixtures.path('test-runner','entry-file','b.test.mjs');
8+
consthelperPath=fixtures.path('test-runner','entry-file','helper.mjs');
9+
10+
asyncfunctioncollectEvents(options){
11+
constevents=[];
12+
conststream=run({files: [aPath,bPath], ...options});
13+
stream.on('test:fail',()=>{});
14+
forawait(consteventofstream){
15+
events.push(event);
16+
}
17+
returnevents;
18+
}
19+
20+
describe('entryFile attribution in reporter events',{concurrency: false},()=>{
21+
it('stamps entryFile on events forwarded from child processes',async()=>{
22+
constevents=awaitcollectEvents({isolation: 'process'});
23+
constchecked={__proto__: null,A: 0,B: 0};
24+
25+
for(const{ type, data }ofevents){
26+
if(data?.name==='restore A'||data?.name==='restore B'){
27+
consttarget=data.name==='restore A' ? 'A' : 'B';
28+
constexpectedEntry=target==='A' ? aPath : bPath;
29+
assert.strictEqual(data.file,helperPath,
30+
`${type} file should be the definition site`);
31+
assert.strictEqual(data.entryFile,expectedEntry,
32+
`${type} entryFile should be the entry file`);
33+
checked[target]++;
34+
}
35+
}
36+
37+
// Each subtest emits at least enqueue/dequeue/start/pass/complete.
38+
assert.ok(checked.A>=4,`expected events for restore A, got ${checked.A}`);
39+
assert.ok(checked.B>=4,`expected events for restore B, got ${checked.B}`);
40+
});
41+
42+
it('stamps entryFile on top-level tests forwarded from child processes',async()=>{
43+
constevents=awaitcollectEvents({isolation: 'process'});
44+
constpass=events.filter(({ type })=>type==='test:pass');
45+
constbackupA=pass.find(({ data })=>data.name==='backup A');
46+
constbackupB=pass.find(({ data })=>data.name==='backup B');
47+
assert.strictEqual(backupA.data.entryFile,aPath);
48+
assert.strictEqual(backupB.data.entryFile,bPath);
49+
});
50+
51+
it('does not stamp entryFile with isolation none',async()=>{
52+
constevents=awaitcollectEvents({isolation: 'none'});
53+
for(const{ data }ofevents){
54+
if(data?.name==='restore A'||data?.name==='restore B'){
55+
assert.strictEqual(data.entryFile,undefined);
56+
}
57+
}
58+
});
59+
});

β€Žtest/parallel/test-runner-v8-deserializer.mjsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, it, beforeEach } from 'node:test';
55
importassertfrom'node:assert';
66
import{finished}from'node:stream/promises';
77
import{DefaultSerializer}from'node:v8';
8+
import{resolve}from'node:path';
89
importserializerfrom'internal/test_runner/reporter/v8-serializer';
910
importrunnerfrom'internal/test_runner/runner';
1011

@@ -14,10 +15,15 @@ async function toArray(chunks) {
1415
returnarr;
1516
}
1617

18+
constentryFile=resolve('filetest');
1719
constdiagnosticEvent={
1820
type: 'test:diagnostic',
1921
data: {nesting: 0,details: {},message: 'diagnostic'},
2022
};
23+
constreportedDiagnosticEvent={
24+
type: 'test:diagnostic',
25+
data: { ...diagnosticEvent.data, entryFile },
26+
};
2127
constchunks=awaittoArray(serializer([diagnosticEvent]));
2228
constdefaultSerializer=newDefaultSerializer();
2329
defaultSerializer.writeHeader();
@@ -67,28 +73,28 @@ describe('v8 deserializer', common.mustCall(() => {
6773
it('should deserialize a chunk with no serialization',async()=>{
6874
constreported=awaitcollectReported([Buffer.from('unknown')]);
6975
assert.deepStrictEqual(reported,[
70-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
76+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
7177
]);
7278
});
7379

7480
it('should deserialize a serialized chunk',async()=>{
7581
constreported=awaitcollectReported(chunks);
76-
assert.deepStrictEqual(reported,[diagnosticEvent]);
82+
assert.deepStrictEqual(reported,[reportedDiagnosticEvent]);
7783
});
7884

7985
it('should deserialize a serialized chunk after non-serialized chunk',async()=>{
8086
constreported=awaitcollectReported([Buffer.concat([Buffer.from('unknown'), ...chunks])]);
8187
assert.deepStrictEqual(reported,[
82-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
83-
diagnosticEvent,
88+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
89+
reportedDiagnosticEvent,
8490
]);
8591
});
8692

8793
it('should deserialize a serialized chunk before non-serialized output',async()=>{
8894
constreported=awaitcollectReported([Buffer.concat([ ...chunks,Buffer.from('unknown')])]);
8995
assert.deepStrictEqual(reported,[
90-
diagnosticEvent,
91-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
96+
reportedDiagnosticEvent,
97+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
9298
]);
9399
});
94100

@@ -131,7 +137,7 @@ describe('v8 deserializer', common.mustCall(() => {
131137
oversizedLengthHeader,
132138
...chunks,
133139
]);
134-
assert.deepStrictEqual(reported.at(-1),diagnosticEvent);
140+
assert.deepStrictEqual(reported.at(-1),reportedDiagnosticEvent);
135141
assert.strictEqual(reported.filter((event)=>event.type==='test:diagnostic').length,1);
136142
assert.strictEqual(collectStdout(reported),oversizedLengthStdout);
137143
});
@@ -152,7 +158,7 @@ describe('v8 deserializer', common.mustCall(() => {
152158
constdata=chunks[0];
153159
constreported=awaitcollectReported([data.subarray(0,i),data.subarray(i)]);
154160
assert.deepStrictEqual(reported,[
155-
diagnosticEvent,
161+
reportedDiagnosticEvent,
156162
]);
157163
});
158164

@@ -163,9 +169,9 @@ describe('v8 deserializer', common.mustCall(() => {
163169
Buffer.concat([data.subarray(i),Buffer.from('unknown')]),
164170
]);
165171
assert.deepStrictEqual(reported,[
166-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
167-
diagnosticEvent,
168-
{data: {__proto__: null,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
172+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
173+
reportedDiagnosticEvent,
174+
{data: {__proto__: null,entryFile,file: 'filetest',message: 'unknown'},type: 'test:stdout'},
169175
]);
170176
}
171177
);

0 commit comments

Comments
Β (0)