|
| 1 | +const { expect } = require('chai') |
| 2 | +const { createTest } = require('../../../lib/mocha/test') |
| 3 | +const { createSuite } = require('../../../lib/mocha/suite') |
| 4 | +const MochaSuite = require('mocha/lib/suite') |
| 5 | +const retryEnhancer = require('../../../lib/listener/retryEnhancer') |
| 6 | +const event = require('../../../lib/event') |
| 7 | + |
| 8 | +describe('Integration test: Retries with CodeceptJS properties', function () { |
| 9 | + beforeEach(function () { |
| 10 | + // Setup the retryEnhancer - this simulates what happens in CodeceptJS init |
| 11 | + retryEnhancer() |
| 12 | + }) |
| 13 | + |
| 14 | + it('should preserve all CodeceptJS properties during real retry scenario', function () { |
| 15 | + // Create a test with retries like: Scenario().retries(2) |
| 16 | + const originalTest = createTest('Test that might fail', () => { |
| 17 | + throw new Error('Simulated failure') |
| 18 | + }) |
| 19 | + |
| 20 | + // Set up test with various CodeceptJS properties that might be used in real scenarios |
| 21 | + originalTest.opts = { |
| 22 | + timeout: 30000, |
| 23 | + metadata: 'important-test', |
| 24 | + retries: 2, |
| 25 | + feature: 'login', |
| 26 | + } |
| 27 | + originalTest.tags = ['@critical', '@smoke', '@login'] |
| 28 | + originalTest.notes = [ |
| 29 | + { type: 'info', text: 'This test validates user login' }, |
| 30 | + { type: 'warning', text: 'May be flaky due to external service' }, |
| 31 | + ] |
| 32 | + originalTest.meta = { |
| 33 | + feature: 'authentication', |
| 34 | + story: 'user-login', |
| 35 | + priority: 'high', |
| 36 | + team: 'qa', |
| 37 | + } |
| 38 | + originalTest.artifacts = ['login-screenshot.png', 'network-log.json'] |
| 39 | + originalTest.uid = 'auth-test-001' |
| 40 | + originalTest.config = { helper: 'playwright', baseUrl: 'http://test.com' } |
| 41 | + originalTest.inject = { userData: { email: '[email protected]' } } |
| 42 | + |
| 43 | + // Add some steps to simulate CodeceptJS test steps |
| 44 | + originalTest.steps = [ |
| 45 | + { title: 'I am on page "/login"', status: 'success' }, |
| 46 | + { title: 'I fill field "email", "[email protected]"', status: 'success' }, |
| 47 | + { title: 'I fill field "password", "secretpassword"', status: 'success' }, |
| 48 | + { title: 'I click "Login"', status: 'failed' }, |
| 49 | + ] |
| 50 | + |
| 51 | + // Enable retries |
| 52 | + originalTest.retries(2) |
| 53 | + |
| 54 | + // Now simulate what happens during mocha retry |
| 55 | + const retriedTest = originalTest.clone() |
| 56 | + |
| 57 | + // Verify that the retried test has reference to original |
| 58 | + expect(retriedTest.retriedTest()).to.equal(originalTest) |
| 59 | + |
| 60 | + // Before our fix, these properties would be lost |
| 61 | + expect(retriedTest.opts || {}).to.deep.equal({}) |
| 62 | + expect(retriedTest.tags || []).to.deep.equal([]) |
| 63 | + |
| 64 | + // Now trigger our retryEnhancer (this happens automatically in CodeceptJS) |
| 65 | + event.emit(event.test.before, retriedTest) |
| 66 | + |
| 67 | + // After our fix, all properties should be preserved |
| 68 | + expect(retriedTest.opts).to.deep.equal({ |
| 69 | + timeout: 30000, |
| 70 | + metadata: 'important-test', |
| 71 | + retries: 2, |
| 72 | + feature: 'login', |
| 73 | + }) |
| 74 | + expect(retriedTest.tags).to.deep.equal(['@critical', '@smoke', '@login']) |
| 75 | + expect(retriedTest.notes).to.deep.equal([ |
| 76 | + { type: 'info', text: 'This test validates user login' }, |
| 77 | + { type: 'warning', text: 'May be flaky due to external service' }, |
| 78 | + ]) |
| 79 | + expect(retriedTest.meta).to.deep.equal({ |
| 80 | + feature: 'authentication', |
| 81 | + story: 'user-login', |
| 82 | + priority: 'high', |
| 83 | + team: 'qa', |
| 84 | + }) |
| 85 | + expect(retriedTest.artifacts).to.deep.equal(['login-screenshot.png', 'network-log.json']) |
| 86 | + expect(retriedTest.uid).to.equal('auth-test-001') |
| 87 | + expect(retriedTest.config).to.deep.equal({ helper: 'playwright', baseUrl: 'http://test.com' }) |
| 88 | + expect(retriedTest.inject).to.deep.equal({ userData: { email: '[email protected]' } }) |
| 89 | + expect(retriedTest.steps).to.deep.equal([ |
| 90 | + { title: 'I am on page "/login"', status: 'success' }, |
| 91 | + { title: 'I fill field "email", "[email protected]"', status: 'success' }, |
| 92 | + { title: 'I fill field "password", "secretpassword"', status: 'success' }, |
| 93 | + { title: 'I click "Login"', status: 'failed' }, |
| 94 | + ]) |
| 95 | + |
| 96 | + // Verify that enhanced methods are available |
| 97 | + expect(retriedTest.addNote).to.be.a('function') |
| 98 | + expect(retriedTest.applyOptions).to.be.a('function') |
| 99 | + expect(retriedTest.simplify).to.be.a('function') |
| 100 | + |
| 101 | + // Test that we can use the methods |
| 102 | + retriedTest.addNote('retry', 'Attempt #2') |
| 103 | + expect(retriedTest.notes).to.have.length(3) |
| 104 | + expect(retriedTest.notes[2]).to.deep.equal({ type: 'retry', text: 'Attempt #2' }) |
| 105 | + |
| 106 | + // Verify the test is enhanced with CodeceptJS functionality |
| 107 | + expect(retriedTest.codeceptjs).to.be.true |
| 108 | + }) |
| 109 | +}) |
0 commit comments