Skip to content

feat: support current datatable for before and after hooks - #5792

Open
kobenguyent wants to merge 1 commit into
4.xfrom
feat-current-support-for-hoooks
Open

kobenguyent wants to merge 1 commit into
4.xfrom
feat-current-support-for-hoooks

Conversation

@kobenguyent

@kobenguyent kobenguyent commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation/Description of the PR

  • Data-driven Before/After hooks

Files Created/Modified:

  1. Core Implementation (lib/data/context.js)
    - Added Before() and After() methods to Data() wrapper
    - Each data row creates a separate hook with current parameter
  2. HookConfig Enhancement (lib/mocha/hooks.js)
    - Added inject() method to HookConfig class for consistency
  3. Unit Tests (test/unit/data/dataDrivenHooks_test.js)
    - 8 tests verifying DataTable structure and row extraction
    - ✅ All passing
  4. Integration Test (test/data/sandbox/dataDrivenHooks_test.dataDrivenHooks.js)
    - Practical example with credentials data table
    - ✅ 2 scenarios passing
  5. Test Config (test/data/sandbox/codecept.dataDrivenHooks.json)
    - Codecept config for running the integration test

How to Run:

Unit tests

npx mocha test/unit/data/dataDrivenHooks_test.js

Integration test

./bin/codecept.js run --config test/data/sandbox/codecept.dataDrivenHooks.json

Usage Example:

const accounts = new DataTable(['login', 'password'])
accounts.add(['alice', 'pass123'])
accounts.add(['bob', 'pass456'])

Data(accounts).Before(({ current }) => {
// Runs once per data row
console.log(Setting up for ${current.login})
})

Data(accounts).After(({ current }) => {
// Cleanup per row
console.log(Cleaning up ${current.login})
})

Scenario('login works', () => {
// Scenarios get injected 'current' via Data() wrapper
})

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)

This branch has not been deployed

No deployments
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.

[feature-request] Send current into Before / After hooks in Data Driven Tests

1 participant