Fix mocha retries losing CodeceptJS-specific properties (opts, tags, meta, etc.) #5099
+413
−2
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.
When using mocha's
retries
functionality withScenario().retries(2)
, CodeceptJS-specific test properties likeopts
,tags
,notes
,meta
, andartifacts
were being lost during retries due to mocha's shallow cloning behavior. This caused issues in hooks and helpers that depend on these properties.Root Cause
Mocha's built-in
test.clone()
method performs a shallow clone that only copies mocha's native properties, losing CodeceptJS enhancements:Solution
Added
retryEnhancer
listener that detects retried tests usingtest.retriedTest()
and copies all CodeceptJS properties from the original test to the retried testEnhanced MochawesomeHelper to correctly handle retried tests by ensuring context is added to the retried test instance, not the original
Comprehensive test coverage to prevent regressions
Changes Made
lib/listener/retryEnhancer.js
- New listener that preserves CodeceptJS properties during retrieslib/codecept.js
- Registered retryEnhancer in the hook chainlib/helper/Mochawesome.js
- Fixed to handle retried tests correctlyImpact
✅ Before:
test.opts
,test.tags
,test.meta
etc. lost during retries✅ After: All CodeceptJS properties preserved across retries
✅ Before: MochawesomeHelper context added to wrong test object
✅ After: Context correctly added to retried test instance
✅ No breaking changes or regressions (412 unit tests pass)
This resolves unexpected behavior mentioned in related issues where retry functionality had unintended consequences for CodeceptJS-specific features.
Fixes #3274.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
googlechromelabs.github.io
node install.mjs
(dns block)https://storage.googleapis.com/chrome-for-testing-public/138.0.7204.168/linux64/chrome-linux64.zip
node install.mjs
(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.