Skip to content

Commit 58f83a1

Browse files
Copilotkobenguyent
andauthored
Fix JUnit XML test case name inconsistency when using scenario retries (#5082)
* Initial plan * Fix JUnit XML test case name inconsistency in scenario retries Co-authored-by: kobenguyent <[email protected]> * Improve edge case handling for empty suite titles in cloned tests Co-authored-by: kobenguyent <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: kobenguyent <[email protected]>
1 parent 93ab75d commit 58f83a1

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

lib/mocha/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ function deserializeTest(test) {
7777
test.parent = Object.assign(new Suite(test.parent?.title || 'Suite'), test.parent)
7878
enhanceMochaSuite(test.parent)
7979
if (test.steps) test.steps = test.steps.map(step => Object.assign(new Step(step.title), step))
80+
81+
// Restore the custom fullTitle function to maintain consistency with original test
82+
if (test.parent) {
83+
test.fullTitle = () => `${test.parent.title}: ${test.title}`
84+
}
85+
8086
return test
8187
}
8288

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types='codeceptjs' />
2+
type steps_file = typeof import('../../support/custom_steps.js')
3+
type MyPage = typeof import('../../support/my_page.js')
4+
type SecondPage = typeof import('../../support/second_page.js')
5+
type CurrentPage = typeof import('./po/custom_steps.js')
6+
7+
declare namespace CodeceptJS {
8+
interface SupportObject {
9+
I: I
10+
current: any
11+
MyPage: MyPage
12+
SecondPage: SecondPage
13+
CurrentPage: CurrentPage
14+
}
15+
interface Methods extends FileSystem {}
16+
interface I extends ReturnType<steps_file>, WithTranslation<Methods> {}
17+
namespace Translation {
18+
interface Actions {}
19+
}
20+
}

test/unit/mocha/test_clone_test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { expect } = require('chai')
2+
const { createTest, cloneTest } = require('../../../lib/mocha/test')
3+
const { createSuite } = require('../../../lib/mocha/suite')
4+
const MochaSuite = require('mocha/lib/suite')
5+
6+
describe('Test cloning for retries', function () {
7+
it('should maintain consistent fullTitle format after cloning', function () {
8+
// Create a root suite first
9+
const rootSuite = new MochaSuite('', null, true)
10+
// Create a test suite as child
11+
const suite = createSuite(rootSuite, 'JUnit reporting')
12+
13+
// Create a test
14+
const test = createTest('Test 1', () => {})
15+
16+
// Add test to suite - this sets up the custom fullTitle function
17+
test.addToSuite(suite)
18+
19+
const originalTitle = test.fullTitle()
20+
expect(originalTitle).to.equal('JUnit reporting: Test 1')
21+
22+
// Clone the test (this is what happens during retries)
23+
const clonedTest = cloneTest(test)
24+
const clonedTitle = clonedTest.fullTitle()
25+
26+
// The cloned test should maintain the same title format with colon
27+
expect(clonedTitle).to.equal(originalTitle)
28+
expect(clonedTitle).to.equal('JUnit reporting: Test 1')
29+
})
30+
31+
it('should preserve parent-child relationship after cloning', function () {
32+
const rootSuite = new MochaSuite('', null, true)
33+
const suite = createSuite(rootSuite, 'Feature Suite')
34+
35+
const test = createTest('Scenario Test', () => {})
36+
test.addToSuite(suite)
37+
38+
const clonedTest = cloneTest(test)
39+
40+
expect(clonedTest.parent).to.exist
41+
expect(clonedTest.parent.title).to.equal('Feature Suite')
42+
expect(clonedTest.fullTitle()).to.equal('Feature Suite: Scenario Test')
43+
})
44+
})

0 commit comments

Comments
 (0)