Skip to content

feat(plugin): JUnit XML reporter plugin with steps & meta#5558

Open
DavertMik wants to merge 1 commit into
4.xfrom
feature/junit-reporter-plugin
Open

feat(plugin): JUnit XML reporter plugin with steps & meta#5558
DavertMik wants to merge 1 commit into
4.xfrom
feature/junit-reporter-plugin

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

What

Adds a built-in junitReporter plugin that writes a standard JUnit-compatible XML report (<testsuites>/<testsuite>/<testcase>) after a test run — consumable by Jenkins, GitLab CI, CircleCI, GitHub Actions test reporters, etc.

Unlike feeding Mocha's mocha-junit-reporter, this plugin understands CodeceptJS, so each <testcase> carries:

  • <properties> — the test's meta information: every meta key from Scenario('...', { meta }), plus its tags and retries
  • <system-out> — an indented step/substep log; substeps are nested under their meta step, and only failed steps are marked ([FAILED] )
  • <failure> — for failed tests: error message, type, stack trace and (optionally) the step trace with the failing step marked
  • <skipped/> for skipped/pending tests

It reads the already-collected test.steps on event.all.result (and event.workers.result, write-once) — no extra per-step listeners — and builds XML with @xmldom/xmldom (already a dependency).

Usage

// codecept.conf.js
plugins: {
  junitReporter: {
    enabled: true,
    // outputName: 'report.xml',
    // output: 'output',
    // testGroupName: 'CodeceptJS',
    // attachMeta: true,
    // attachSteps: true,
    // stepsInFailure: true,
  }
}
npx codeceptjs run -p junitReporter
npx codeceptjs run -p junitReporter:outputName=junit.xml

Sample output

<testcase name="logs in successfully" classname="Login" time="1.234" file="...">
  <properties>
    <property name="severity" value="critical"/>
    <property name="owner" value="qa-team"/>
    <property name="tags" value="@important @smoke"/>
  </properties>
  <system-out>I am on page "/login" (42ms)
On user: login "joe" (310ms)
  I fill field "login", "joe" (42ms)
  I click "Sign in" (42ms)
I see "Welcome" (42ms)</system-out>
</testcase>

Notes / limitations

  • With run-workers, steps are serialized between processes so substep nesting flattens to one level (same constraint as aiTrace etc.); pass/fail/skip/timings/meta still recorded.

Files

  • lib/plugin/junitReporter.js — the plugin (+ JSDoc, which feeds docs/plugins.md)
  • test/unit/junitReporter_test.js — unit tests (well-formedness, <properties> = meta, <system-out> step tree, failures, skipped, custom filename, write-once)
  • docs/plugins.md## junitReporter section

Test plan

  • npx mocha test/unit/junitReporter_test.js — 8 passing
  • eslint clean
  • End-to-end smoke: node bin/codecept.js run --config test/data/sandbox/codecept.js -p junitReporter writes a valid output/report.xml with multiple suites, tags and step logs

🤖 Generated with Claude Code

New built-in `junitReporter` plugin that writes a standard JUnit
`<testsuites>/<testsuite>/<testcase>` XML report after a run, consumable
by Jenkins, GitLab CI, CircleCI, GitHub Actions test reporters, etc.

Beyond plain pass/fail/skip + durations + error stack, each `<testcase>`
includes CodeceptJS-specific data Mocha's reporter can't provide:

- `<properties>` — the test's meta information: every `meta` key from
  `Scenario('...', { meta })`, plus its `tags` and `retries`
- `<system-out>` — an indented step/substep log; substeps nested under
  their meta step, only failed steps marked
- `<failure>` — message, type, stack, and (optionally) the step trace

Reads the already-collected `test.steps` on `event.all.result`
(and `event.workers.result`); builds XML via `@xmldom/xmldom`.

Config: `outputName`, `output`, `testGroupName`, `attachMeta`,
`attachSteps`, `stepsInFailure`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant