Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 23, 2025

When using mocha's retries functionality with Scenario().retries(2), CodeceptJS-specific test properties like opts, tags, notes, meta, and artifacts 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:

// Before retry: test has CodeceptJS properties
test.opts = { timeout: 5000, metadata: 'test-data' }
test.tags = ['@smoke', '@regression'] 
test.meta = { feature: 'login' }

// After mocha retry: properties are lost
retriedTest.opts // undefined
retriedTest.tags // undefined  
retriedTest.meta // undefined

Solution

  1. Added retryEnhancer listener that detects retried tests using test.retriedTest() and copies all CodeceptJS properties from the original test to the retried test

  2. Enhanced MochawesomeHelper to correctly handle retried tests by ensuring context is added to the retried test instance, not the original

  3. Comprehensive test coverage to prevent regressions

Changes Made

  • lib/listener/retryEnhancer.js - New listener that preserves CodeceptJS properties during retries
  • lib/codecept.js - Registered retryEnhancer in the hook chain
  • lib/helper/Mochawesome.js - Fixed to handle retried tests correctly
  • Test files - Added comprehensive test coverage for retry scenarios

Impact

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
    • Triggering command: node install.mjs (dns block)
  • https://storage.googleapis.com/chrome-for-testing-public/138.0.7204.168/linux64/chrome-linux64.zip
    • Triggering command: 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.

@Copilot Copilot AI changed the title [WIP] Mocha's retries implementation has unexpected consenquences Fix mocha retries losing CodeceptJS-specific properties (opts, tags, meta, etc.) Aug 23, 2025
@Copilot Copilot AI requested a review from kobenguyent August 23, 2025 05:08
Copilot finished work on behalf of kobenguyent August 23, 2025 05:08
@kobenguyent kobenguyent marked this pull request as ready for review August 23, 2025 06:39
@kobenguyent kobenguyent merged commit 5598d39 into 3.x Aug 23, 2025
24 of 25 checks passed
@kobenguyent kobenguyent deleted the copilot/fix-3274 branch August 23, 2025 14:43
Copilot AI added a commit that referenced this pull request Sep 1, 2025
@kobenguyent kobenguyent mentioned this pull request Sep 22, 2025
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.

Mocha's retries implementation has unexpected consenquences
3 participants