diff --git a/lib/mocha/test.js b/lib/mocha/test.js
index 7ff53721d..e4a33f346 100644
--- a/lib/mocha/test.js
+++ b/lib/mocha/test.js
@@ -77,6 +77,12 @@ function deserializeTest(test) {
test.parent = Object.assign(new Suite(test.parent?.title || 'Suite'), test.parent)
enhanceMochaSuite(test.parent)
if (test.steps) test.steps = test.steps.map(step => Object.assign(new Step(step.title), step))
+
+ // Restore the custom fullTitle function to maintain consistency with original test
+ if (test.parent) {
+ test.fullTitle = () => `${test.parent.title}: ${test.title}`
+ }
+
return test
}
diff --git a/test/data/sandbox/configs/definitions/steps.d.ts b/test/data/sandbox/configs/definitions/steps.d.ts
new file mode 100644
index 000000000..41dc21a1e
--- /dev/null
+++ b/test/data/sandbox/configs/definitions/steps.d.ts
@@ -0,0 +1,20 @@
+///
+type steps_file = typeof import('../../support/custom_steps.js')
+type MyPage = typeof import('../../support/my_page.js')
+type SecondPage = typeof import('../../support/second_page.js')
+type CurrentPage = typeof import('./po/custom_steps.js')
+
+declare namespace CodeceptJS {
+ interface SupportObject {
+ I: I
+ current: any
+ MyPage: MyPage
+ SecondPage: SecondPage
+ CurrentPage: CurrentPage
+ }
+ interface Methods extends FileSystem {}
+ interface I extends ReturnType, WithTranslation {}
+ namespace Translation {
+ interface Actions {}
+ }
+}
diff --git a/test/unit/mocha/test_clone_test.js b/test/unit/mocha/test_clone_test.js
new file mode 100644
index 000000000..dc5a1b1ba
--- /dev/null
+++ b/test/unit/mocha/test_clone_test.js
@@ -0,0 +1,44 @@
+const { expect } = require('chai')
+const { createTest, cloneTest } = require('../../../lib/mocha/test')
+const { createSuite } = require('../../../lib/mocha/suite')
+const MochaSuite = require('mocha/lib/suite')
+
+describe('Test cloning for retries', function () {
+ it('should maintain consistent fullTitle format after cloning', function () {
+ // Create a root suite first
+ const rootSuite = new MochaSuite('', null, true)
+ // Create a test suite as child
+ const suite = createSuite(rootSuite, 'JUnit reporting')
+
+ // Create a test
+ const test = createTest('Test 1', () => {})
+
+ // Add test to suite - this sets up the custom fullTitle function
+ test.addToSuite(suite)
+
+ const originalTitle = test.fullTitle()
+ expect(originalTitle).to.equal('JUnit reporting: Test 1')
+
+ // Clone the test (this is what happens during retries)
+ const clonedTest = cloneTest(test)
+ const clonedTitle = clonedTest.fullTitle()
+
+ // The cloned test should maintain the same title format with colon
+ expect(clonedTitle).to.equal(originalTitle)
+ expect(clonedTitle).to.equal('JUnit reporting: Test 1')
+ })
+
+ it('should preserve parent-child relationship after cloning', function () {
+ const rootSuite = new MochaSuite('', null, true)
+ const suite = createSuite(rootSuite, 'Feature Suite')
+
+ const test = createTest('Scenario Test', () => {})
+ test.addToSuite(suite)
+
+ const clonedTest = cloneTest(test)
+
+ expect(clonedTest.parent).to.exist
+ expect(clonedTest.parent.title).to.equal('Feature Suite')
+ expect(clonedTest.fullTitle()).to.equal('Feature Suite: Scenario Test')
+ })
+})