Skip to content

Commit ffd4eb9

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <[email protected]>
1 parent 1c65ea8 commit ffd4eb9

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/plugin/stepByStepReport.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const templates = {}
4040
* npx codeceptjs run --plugins stepByStepReport
4141
* ```
4242
*
43+
* Run tests with workers:
44+
*
45+
* ```
46+
* npx codeceptjs run-workers 2 --plugins stepByStepReport
47+
* ```
48+
*
4349
* #### Configuration
4450
*
4551
* ```js
@@ -60,6 +66,11 @@ const templates = {}
6066
* * `screenshotsForAllureReport`: If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. Default: false.
6167
* * `disableScreenshotOnFail : Disables the capturing of screeshots after the failed step. Default: true.
6268
*
69+
* #### Worker Support
70+
*
71+
* When using `run-workers`, screenshots from all workers are automatically consolidated into a shared directory
72+
* to ensure the final step-by-step report contains all screenshots from all workers.
73+
*
6374
* @param {*} config
6475
*/
6576

@@ -87,7 +98,25 @@ module.exports = function (config) {
8798

8899
const recordedTests = {}
89100
const pad = '0000'
90-
const reportDir = config.output ? path.resolve(global.codecept_dir, config.output) : defaultConfig.output
101+
102+
// When running with workers, use the shared output directory instead of worker-specific directories
103+
// This ensures that all workers save their screenshots to the same location so the final consolidated
104+
// report can find all screenshots in one place
105+
let reportDir
106+
if (process.env.RUNS_WITH_WORKERS === 'true' && global.codecept_dir) {
107+
// Extract the base output directory from the worker-specific path
108+
// Worker paths are typically like: /project/output/worker_name
109+
// We want to extract: /project/output and create: /project/output/stepByStepReport
110+
const currentOutputDir = config.output ? path.resolve(global.codecept_dir, config.output) : defaultConfig.output
111+
const workerDirPattern = /[/\\][^/\\]+$/ // Match the last directory segment (worker name)
112+
const baseOutputDir = currentOutputDir.replace(workerDirPattern, '')
113+
reportDir = path.join(baseOutputDir, 'stepByStepReport')
114+
} else {
115+
reportDir = config.output ? path.resolve(global.codecept_dir, config.output) : defaultConfig.output
116+
}
117+
118+
// Ensure the report directory exists
119+
mkdirp.sync(reportDir)
91120

92121
event.dispatcher.on(event.suite.before, suite => {
93122
stepNum = -1

test/unit/worker_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,34 @@ describe('Workers', function () {
264264
done()
265265
})
266266
})
267+
268+
it('should handle stepByStep reporter directory resolution with workers', () => {
269+
const path = require('path')
270+
271+
// Mock the stepByStep directory resolution logic
272+
function getStepByStepReportDir(config, isWorker, globalCodeceptDir) {
273+
let reportDir
274+
if (isWorker && globalCodeceptDir) {
275+
const currentOutputDir = config.output ? path.resolve(globalCodeceptDir, config.output) : '/default-output'
276+
const workerDirPattern = /[/\\][^/\\]+$/
277+
const baseOutputDir = currentOutputDir.replace(workerDirPattern, '')
278+
reportDir = path.join(baseOutputDir, 'stepByStepReport')
279+
} else {
280+
reportDir = config.output ? path.resolve(globalCodeceptDir, config.output) : '/default-output'
281+
}
282+
return reportDir
283+
}
284+
285+
const globalCodeceptDir = '/tmp/test'
286+
287+
// Test regular (non-worker) mode
288+
const regularConfig = { output: './output' }
289+
const regularDir = getStepByStepReportDir(regularConfig, false, globalCodeceptDir)
290+
expect(regularDir).equal('/tmp/test/output')
291+
292+
// Test worker mode
293+
const workerConfig = { output: './output/worker1' }
294+
const workerDir = getStepByStepReportDir(workerConfig, true, globalCodeceptDir)
295+
expect(workerDir).equal('/tmp/test/output/stepByStepReport')
296+
})
267297
})

0 commit comments

Comments
 (0)