Repository navigation
feat: support current datatable for before and after hooks - #5792
Merged
Merged
Conversation
Collaborator
|
@kobenguyent Thanks for picking up issue. The hooks currently aren't bound to data iterations: Data(table).Before() registers one suite-level hook per row, and suite-level hooks run before every test in the file — so all rows fire on every run instead of once per row. They should bind to the generated scenario for that row (like Data().Scenario() does .inject({ current }) per test). Also: the integration test accumulates hookCalls but never asserts them; the unit tests cover DataTable (pre-existing code) rather than the new methods; HookConfig.inject() is added but never used. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation/Description of the PR
Files Created/Modified:
- Added Before() and After() methods to Data() wrapper
- Each data row creates a separate hook with current parameter
- Added inject() method to HookConfig class for consistency
- 8 tests verifying DataTable structure and row extraction
- ✅ All passing
- Practical example with credentials data table
- ✅ 2 scenarios passing
- 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
})
currentintoBefore/Afterhooks in Data Driven Tests #1243.Type of change
Checklist:
npm run docs)npm run lint)npm test)