Skip to content

test(gherkin): cover event.test.before/after payload regression#5582

Merged
DavertMik merged 1 commit into
4.xfrom
feat/bdd-tests
May 27, 2026
Merged

test(gherkin): cover event.test.before/after payload regression#5582
DavertMik merged 1 commit into
4.xfrom
feat/bdd-tests

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

@DavertMik DavertMik commented May 27, 2026

Added tests covering #5580

Summary

Adds three layers of test coverage for the bug fixed in #5580 (770749e1), where the Gherkin beforeEach hook emitted event.test.before with a placeholder test (title "...", empty tags) because the asyncWrapper read suite.ctx.currentTest from a Mocha hook Context that only had currentTest directly. The regression silently broke every listener of event.test.before (@testomatio/reporter, screenshot, heal, customReporter, aiTrace, screencast, globalTimeout, globalRetry, retryFailedStep, the workers IPC bridge, …) for BDD scenarios.

  • Unit (test/unit/bdd_test.js) — 6 new tests in a Gherkin hook events block. They drive the codeceptjs.before / codeceptjs.after hooks with a synthetic Mocha hook Context ({ currentTest }) and assert the real scenario title and tags reach event.test.before, event.test.after, the Before/After step-definition hooks, that done is forwarded exactly once, and that the event ordering test.before → test.started → test.passed → test.after is preserved.
  • Runner (test/runner/bdd_test.js + test/data/sandbox/) — new capture plugin (support/capture_test_before.js) and config (codecept.bdd.events.js) serialize event.test.before/after payloads to a temp JSON file. A spawned runner asserts the real @important / @very tags and scenario title reach listeners end-to-end.
  • Acceptance (test/acceptance/gherkin/before_hook.feature + steps.js) — new Background + tagged scenario. The Then step verifies both the BDD Before() hook and a direct event.test.before listener captured the real scenario title/tags.

Also flips the suite?.ctx?.currentTest ?? suite?.currentTest precedence in setup/teardown so the regular Scenario path keeps using ctx.currentTest while the BDD hook Context still falls back to currentTest.

Verified the new tests catch the regression: reverting setup/teardown to the pre-fix enhanceMochaTest(suite?.ctx?.currentTest) makes 2/6 unit tests, the runner test, and the acceptance test fail with the placeholder "..." title. Restoring the fix makes them all pass.

Test plan

  • npx mocha test/unit/bdd_test.js --timeout 10000 — 24 passing (6 new + 18 existing)
  • npx mocha test/runner/bdd_test.js --timeout 60000 --grep "emits event.test.before" — 1 passing
  • ./bin/codecept.js run --config test/acceptance/codecept.Playwright.js --grep "@hookCapture" --verbose — passes against the PHP test app on :8000
  • Reverting lib/mocha/asyncWrapper.js to the pre-fix code causes all three new layers to fail with the placeholder "..." title; restoring the fix makes them pass
  • Cross-check against ~/projects/testomatio/examples/codeceptjs-cucumber/ — scenarios now report with real titles and @T… tags

🤖 Generated with Claude Code

Adds three layers of coverage for the bug fixed in 770749e (gherkin
beforeEach/afterEach emitting event.test.before with a placeholder test
when the hook Context lacked .ctx.currentTest):

* Unit (test/unit/bdd_test.js): six tests in a new "Gherkin hook events"
  block that drive the codeceptjs.before/after hooks with a mock Mocha
  Context and assert the real scenario title and tags reach
  event.test.before, event.test.after, the Before/After step-definition
  hooks, and that done is forwarded.
* Runner (test/runner/bdd_test.js + test/data/sandbox): a capture plugin
  and codecept.bdd.events.js config that serialize event payloads to a
  temp JSON file so a spawned runner asserts the real @important/@very
  tags reach listeners end-to-end.
* Acceptance (test/acceptance/gherkin/before_hook.feature + steps.js):
  a new Background+tagged feature whose Then step verifies both the BDD
  Before() hook and a direct event.test.before listener captured the
  real scenario.

Also flips setup/teardown to prefer suite.ctx.currentTest over
suite.currentTest, restoring the regular Scenario path while keeping the
BDD fallback.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@DavertMik DavertMik merged commit 6c7e718 into 4.x May 27, 2026
10 checks passed
@DavertMik DavertMik deleted the feat/bdd-tests branch May 27, 2026 21:16
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