Skip to content

fix(gherkin): emit test.before/after with real current test#5580

Merged
DavertMik merged 1 commit into
codeceptjs:4.xfrom
danikkrapivnitskiy:fix/bdd-gherkin-test-before-current-test
May 27, 2026
Merged

fix(gherkin): emit test.before/after with real current test#5580
DavertMik merged 1 commit into
codeceptjs:4.xfrom
danikkrapivnitskiy:fix/bdd-gherkin-test-before-current-test

Conversation

@danikkrapivnitskiy
Copy link
Copy Markdown
Contributor

Gherkin beforeEach/afterEach pass Mocha hook Context into setup/teardown, but asyncWrapper read suite.ctx.currentTest (undefined on Context), so event.test.before received a placeholder test (title "...", empty tags).

Also forward Mocha's done callback instead of no-op () => {}, so event.test.before completes before scenario Background Before hooks run.

Motivation/Description of the PR

  • Description of this PR, which problem it solves
  • Resolves #issueId (if applicable).

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium

Applicable plugins:

  • aiTrace
  • autoDelay
  • autoLogin
  • customLocator
  • pause
  • coverage
  • heal
  • retryFailedStep
  • screenshot
  • selenoid
  • stepTimeout
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

Gherkin beforeEach/afterEach pass Mocha hook Context into setup/teardown,
but asyncWrapper read suite.ctx.currentTest (undefined on Context), so
event.test.before received a placeholder test (title "...", empty tags).

Also forward Mocha's done callback instead of no-op () => {}, so
event.test.before completes before scenario Background Before hooks run.

Co-authored-by: Cursor <cursoragent@cursor.com>
@DavertMik
Copy link
Copy Markdown
Contributor

@danikkrapivnitskiy looks good but I would prefer to see an acceptance test for this case
This might affect all other changes so I need guarantee this won't cause sideeffects

Also if possible I would prefer opposite order:

suite?.ctx?.currentTest ?? suite?.currentTest

@DavertMik
Copy link
Copy Markdown
Contributor

I checked the fix work fine for BDD projects

@DavertMik DavertMik merged commit 770749e into codeceptjs:4.x May 27, 2026
10 checks passed
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.

3 participants