Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/mocha/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
20 changes: 20 additions & 0 deletions test/data/sandbox/configs/definitions/steps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference types='codeceptjs' />
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<steps_file>, WithTranslation<Methods> {}
namespace Translation {
interface Actions {}
}
}
44 changes: 44 additions & 0 deletions test/unit/mocha/test_clone_test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
Loading