Skip to content

run-workers: Step.simplify() drops metaStep and JSON-serializes locators, so main-process reporters lose within()/section nesting #5820

Backlog

Description

@mirao

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:

  1. metaStep is dropped. Only parent.title = step.metaStep.actor is kept, so step.metaStep is undefined in the main process. Any reporter or plugin that groups steps by meta step (within(), page-object methods, Section) shows them flat. The built-in junitReporter plugin walks step.metaStep as well.
  2. Object arguments become raw JSON. JSON.stringify(arg).slice(0, 300) turns a locator into a string, so step.toString() gives I click "{"type":"xpath","output":null,...}" instead of I 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 🐛

image

run-multiple ✔️

image

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 in deserializeStep() / deserializeTest() rebuild it as MetaStep instances. Steps that shared one MetaStep in 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 by step.metaStep).
  • For Locator arguments (and other objects with a meaningful toString()), send arg.toString() instead of JSON.stringify(arg).slice(0, 300).

Created by AI agent (Claude Code)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions