|  | 
|  | 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