@@ -12,6 +12,8 @@ const {
1212 JEST_WORKER_COVERAGE_PAYLOAD_CODE ,
1313 CUCUMBER_WORKER_TRACE_PAYLOAD_CODE ,
1414 MOCHA_WORKER_TRACE_PAYLOAD_CODE ,
15+ PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE ,
16+ VITEST_WORKER_TRACE_PAYLOAD_CODE ,
1517} = require ( '../../../../src/plugins/util/test' )
1618
1719describe ( 'CI Visibility Test Worker Exporter' , ( ) => {
@@ -122,4 +124,73 @@ describe('CI Visibility Test Worker Exporter', () => {
122124 sinon . assert . notCalled ( send )
123125 } )
124126 } )
127+
128+ context ( 'when the process is a playwright worker' , ( ) => {
129+ beforeEach ( ( ) => {
130+ process . env . DD_PLAYWRIGHT_WORKER = '1'
131+ } )
132+ afterEach ( ( ) => {
133+ delete process . env . DD_PLAYWRIGHT_WORKER
134+ } )
135+
136+ it ( 'can export traces' , ( ) => {
137+ const trace = [ { type : 'test' } ]
138+ const traceSecond = [ { type : 'test' , name : 'other' } ]
139+ const playwrightWorkerExporter = new TestWorkerCiVisibilityExporter ( )
140+ playwrightWorkerExporter . export ( trace )
141+ playwrightWorkerExporter . export ( traceSecond )
142+ playwrightWorkerExporter . flush ( )
143+ sinon . assert . calledWith ( send , [ PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE , JSON . stringify ( [ trace , traceSecond ] ) ] )
144+ } )
145+
146+ it ( 'does not break if process.send is undefined' , ( ) => {
147+ delete process . send
148+ const trace = [ { type : 'test' } ]
149+ const playwrightWorkerExporter = new TestWorkerCiVisibilityExporter ( )
150+ playwrightWorkerExporter . export ( trace )
151+ playwrightWorkerExporter . flush ( )
152+ sinon . assert . notCalled ( send )
153+ } )
154+ } )
155+
156+ context ( 'when the process is a vitest worker' , ( ) => {
157+ afterEach ( ( ) => {
158+ delete process . env . DD_VITEST_WORKER
159+ delete process . env . TINYPOOL_WORKER_ID
160+ } )
161+
162+ it ( 'can export traces (vitest >=4)' , ( ) => {
163+ process . env . DD_VITEST_WORKER = '1'
164+ const trace = [ { type : 'test' } ]
165+ const traceSecond = [ { type : 'test' , name : 'other' } ]
166+ const vitestWorkerExporter = new TestWorkerCiVisibilityExporter ( )
167+ vitestWorkerExporter . export ( trace )
168+ vitestWorkerExporter . export ( traceSecond )
169+ vitestWorkerExporter . flush ( )
170+ sinon . assert . calledWith ( send , [ VITEST_WORKER_TRACE_PAYLOAD_CODE , JSON . stringify ( [ trace , traceSecond ] ) ] )
171+ } )
172+
173+ it ( 'wraps the payload for legacy tinypool workers (vitest <4)' , ( ) => {
174+ process . env . TINYPOOL_WORKER_ID = '1'
175+ const trace = [ { type : 'test' } ]
176+ const vitestWorkerExporter = new TestWorkerCiVisibilityExporter ( )
177+ vitestWorkerExporter . export ( trace )
178+ vitestWorkerExporter . flush ( )
179+ sinon . assert . calledWith ( send , {
180+ __tinypool_worker_message__ : true ,
181+ interprocessCode : VITEST_WORKER_TRACE_PAYLOAD_CODE ,
182+ data : JSON . stringify ( [ trace ] ) ,
183+ } )
184+ } )
185+
186+ it ( 'does not break if process.send is undefined' , ( ) => {
187+ process . env . DD_VITEST_WORKER = '1'
188+ delete process . send
189+ const trace = [ { type : 'test' } ]
190+ const vitestWorkerExporter = new TestWorkerCiVisibilityExporter ( )
191+ vitestWorkerExporter . export ( trace )
192+ vitestWorkerExporter . flush ( )
193+ sinon . assert . notCalled ( send )
194+ } )
195+ } )
125196} )
0 commit comments