@@ -269,29 +269,73 @@ describe('Workers', function () {
269269 const path = require ( 'path' )
270270
271271 // Mock the stepByStep directory resolution logic
272- function getStepByStepReportDir ( config , isWorker , globalCodeceptDir ) {
272+ function getStepByStepReportDir ( config , isRunningWithWorkers , isRunMultipleChild , globalCodeceptDir ) {
273+ const needsConsolidation = isRunningWithWorkers || isRunMultipleChild
273274 let reportDir
274- if ( isWorker && globalCodeceptDir ) {
275+
276+ if ( needsConsolidation && globalCodeceptDir ) {
275277 const currentOutputDir = config . output ? path . resolve ( globalCodeceptDir , config . output ) : '/default-output'
276- const workerDirPattern = / [ / \\ ] [ ^ / \\ ] + $ /
277- const baseOutputDir = currentOutputDir . replace ( workerDirPattern , '' )
278+
279+ let baseOutputDir = currentOutputDir
280+
281+ // For mixed scenario (run-multiple + workers), we need to strip both worker and run directory segments
282+ // For run-workers only, strip worker directory segment
283+ // For run-multiple only, strip run directory segment
284+ if ( isRunningWithWorkers ) {
285+ // Strip worker directory: /output/smoke_chrome_hash_1/worker1 -> /output/smoke_chrome_hash_1 or /output/worker1 -> /output
286+ const workerDirPattern = / [ / \\ ] [ ^ / \\ ] + $ / // Match the last directory segment (worker name)
287+ baseOutputDir = baseOutputDir . replace ( workerDirPattern , '' )
288+ }
289+
290+ if ( isRunMultipleChild ) {
291+ // Strip run directory: /output/smoke_chrome_hash_1 -> /output
292+ const runDirPattern = / [ / \\ ] [ ^ / \\ ] + $ / // Match the last directory segment (run name)
293+ baseOutputDir = baseOutputDir . replace ( runDirPattern , '' )
294+ }
295+
278296 reportDir = path . join ( baseOutputDir , 'stepByStepReport' )
279297 } else {
280298 reportDir = config . output ? path . resolve ( globalCodeceptDir , config . output ) : '/default-output'
281299 }
300+
282301 return reportDir
283302 }
284303
285304 const globalCodeceptDir = '/tmp/test'
286305
287- // Test regular (non-worker) mode
306+ // Test regular (non-worker) mode with default directory
288307 const regularConfig = { output : './output' }
289- const regularDir = getStepByStepReportDir ( regularConfig , false , globalCodeceptDir )
308+ const regularDir = getStepByStepReportDir ( regularConfig , false , false , globalCodeceptDir )
290309 expect ( regularDir ) . equal ( '/tmp/test/output' )
291310
292- // Test worker mode
311+ // Test regular (non-worker) mode with custom directory
312+ const customConfig = { output : './custom-output' }
313+ const customDir = getStepByStepReportDir ( customConfig , false , false , globalCodeceptDir )
314+ expect ( customDir ) . equal ( '/tmp/test/custom-output' )
315+
316+ // Test run-workers mode with default directory
293317 const workerConfig = { output : './output/worker1' }
294- const workerDir = getStepByStepReportDir ( workerConfig , true , globalCodeceptDir )
318+ const workerDir = getStepByStepReportDir ( workerConfig , true , false , globalCodeceptDir )
295319 expect ( workerDir ) . equal ( '/tmp/test/output/stepByStepReport' )
320+
321+ // Test run-workers mode with custom directory
322+ const workerCustomConfig = { output : './custom-output/worker2' }
323+ const workerCustomDir = getStepByStepReportDir ( workerCustomConfig , true , false , globalCodeceptDir )
324+ expect ( workerCustomDir ) . equal ( '/tmp/test/custom-output/stepByStepReport' )
325+
326+ // Test run-multiple mode with default directory
327+ const multipleConfig = { output : './output/smoke_chrome_hash_1' }
328+ const multipleDir = getStepByStepReportDir ( multipleConfig , false , true , globalCodeceptDir )
329+ expect ( multipleDir ) . equal ( '/tmp/test/output/stepByStepReport' )
330+
331+ // Test run-multiple mode with custom directory
332+ const multipleCustomConfig = { output : './custom-output/regression_firefox_hash_2' }
333+ const multipleCustomDir = getStepByStepReportDir ( multipleCustomConfig , false , true , globalCodeceptDir )
334+ expect ( multipleCustomDir ) . equal ( '/tmp/test/custom-output/stepByStepReport' )
335+
336+ // Test mixed run-multiple + workers mode
337+ const mixedConfig = { output : './output/smoke_chrome_hash_1/worker1' }
338+ const mixedDir = getStepByStepReportDir ( mixedConfig , true , true , globalCodeceptDir )
339+ expect ( mixedDir ) . equal ( '/tmp/test/output/stepByStepReport' )
296340 } )
297341} )
0 commit comments