Skip to content

fix(junitReporter): stamp suites with their real start time - #5683

Open
luantaraschi wants to merge 1 commit into
codeceptjs:4.xfrom
luantaraschi:fix/suite-started-at
Open

fix(junitReporter): stamp suites with their real start time#5683
luantaraschi wants to merge 1 commit into
codeceptjs:4.xfrom
luantaraschi:fix/suite-started-at

Conversation

@luantaraschi

Copy link
Copy Markdown

Motivation/Description of the PR

Resolves #5668.

junitReporter writes each <testsuite timestamp> from suite.startedAt (lib/plugin/junitReporter.js:135), but nothing ever set that field. Confirming @mirao's read: startedAt is assigned in exactly one place, lib/listener/steps.js:20, and only to individual tests. Mocha's Suite does not carry it. So toIso() always fell through to its new Date() fallback and every suite got stamped with the moment the XML was serialized, which is after that suite and its AfterSuite had already finished.

The steps listener now stamps the suite on event.suite.before, mirroring what it already does for tests two lines below.

One thing worth flagging: the existing junitReporter_test.js builds its fixtures with startedAt: Date.now() on each suite object, so the tests were exercising a field that production never produced. That is why the reporter's own suite passed while the output was wrong. I left those fixtures alone since they now describe reality, and put the new coverage on the listener instead.

Scope note: this covers the in-process run. Under run-workers, lib/mocha/test.js serializes a test's parent down to { title } and drops startedAt from the test payload as well, so a suite timestamp cannot cross that boundary without changing the worker payload. That looked like a separate change, so I left it out rather than widen this PR.

Type of change

  • 🐛 Bug fix

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs) — N/A, no public API change
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

Two tests in test/unit/listener/steps_suite_started_at_test.js. They fail on the commit before this change with expected undefined to be a number, and pass with it.

Full unit suite on Windows: 758 passing / 13 failing before, 760 passing / 11 failing after. The 11 remaining failures are pre-existing path assertions that expect POSIX-style paths and see a C: drive letter (utils_test.js, utils/trace_test.js); they are identical with and without this change.

junitReporter writes each `<testsuite timestamp>` from `suite.startedAt`,
but nothing ever set that field. Mocha's Suite does not carry it, and
`startedAt` was only assigned to individual tests, in
lib/listener/steps.js. So `toIso()` always fell through to its
`new Date()` fallback and every suite was stamped with the moment the XML
was serialized, which is after the suite (and its AfterSuite) finished.

The steps listener now stamps the suite on `event.suite.before`, mirroring
what it already does for tests.

Note this covers the in-process run. Under `run-workers` the parent only
receives `{ title }` for a test's parent suite, so the timestamp cannot
survive that boundary without changing the worker payload.

Closes codeceptjs#5668
Copilot AI lite review requested due to automatic review settings August 7, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

junitReporter: per-<testsuite> timestamp uses report-write time, not suite-start time

2 participants