Repository navigation
Description
What's wrong
Under run-workers, every step event and test.steps that reach the main process go through Step.simplify() (lib/step/base.js) and are rebuilt by deserializeStep() / deserializeTest(). simplify() loses two things a plain run gives every listener:
metaStepis dropped. Onlyparent.title = step.metaStep.actoris kept, sostep.metaStepisundefinedin the main process. Any reporter or plugin that groups steps by meta step (within(), page-object methods,Section) shows them flat. The built-injunitReporterplugin walksstep.metaStepas well.- Object arguments become raw JSON.
JSON.stringify(arg).slice(0, 300)turns a locator into a string, sostep.toString()givesI click "{"type":"xpath","output":null,...}"instead ofI click {xpath: ...}. Long locators are also cut at 300 chars.
The per-worker console output (--verbose) is fine because it is printed inside the worker from the real Step objects. Only listeners in the main process are affected.
We hit this with the Testomatio reporter HTML report: steps inside within() are nested under a "Within ..." section with run-multiple and come out flat with run-workers.
run-workers 🐛
run-multiple ✔️
Minimal reproduction (no browser needed)
package.json
{ "type": "module" }DummyHelper.js
import Helper from '@codeceptjs/helper'
export default class DummyHelper extends Helper {
async _withinBegin() {}
async _withinEnd() {}
async click() {}
async see() {}
}printSteps.js, a plugin that prints what a main-process reporter receives
import { event } from 'codeceptjs'
export default function () {
event.dispatcher.on(event.test.after, test => {
for (const s of test.steps) {
console.log(`[reporter] ${s.toString()} | metaStep=${s.metaStep ? s.metaStep.toString() : 'undefined'}`)
}
})
}codecept.conf.js
export const config = {
tests: './*_test.js',
output: './output',
helpers: { DummyHelper: { require: './DummyHelper.js' } },
plugins: { printSteps: { require: './printSteps.js', enabled: true } },
name: 'repro',
}within_test.js
Feature('Within')
Scenario('steps inside within', ({ I }) => {
I.click('.outside')
within('.modal', () => {
I.see('Inside')
I.click(locate('button').withText('OK'))
})
})npx codeceptjs run: correct
[reporter] I click ".outside" | metaStep=undefined
[reporter] I see "Inside" | metaStep=Within ".modal"
[reporter] I click {xpath: //button[contains(., 'OK')]} | metaStep=Within ".modal"
npx codeceptjs run-workers 1: metaStep lost, locator serialized as JSON
[reporter] I click ".outside" | metaStep=undefined
[reporter] I see "Inside" | metaStep=undefined
[reporter] I click "{"type":"xpath","output":null,"strict":true,"locator":{"xpath":"//button[contains(., 'OK')]"},"value":"//button[contains(., 'OK')]"}" | metaStep=undefined
Reproduced with CodeceptJS 4.2.4 on Node 24.18.0 and on Bun. simplify() is the same in 4.2.6 and on 4.x.
Suggested fix
- In
Step.simplify(), serialize the meta-step chain (e.g.metaStep: { actor, title, args, status, startTime, endTime, metaStep: ... }), and indeserializeStep()/deserializeTest()rebuild it asMetaStepinstances. Steps that shared oneMetaStepin the worker should share one instance after deserialization too (e.g. matched by an id), because reporters usually group by object identity (new Map()keyed bystep.metaStep). - For
Locatorarguments (and other objects with a meaningfultoString()), sendarg.toString()instead ofJSON.stringify(arg).slice(0, 300).
Created by AI agent (Claude Code)
Activity