Skip to content

Commit 094680b

Browse files
committed
fix: preserve test artifacts on retry
1 parent eb1bcdc commit 094680b

4 files changed

Lines changed: 55 additions & 2 deletions

File tree

lib/listener/retryEnhancer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function copyCodeceptJSProperties(originalTest, retriedTest) {
4444
}
4545

4646
if (originalTest.artifacts !== undefined) {
47-
retriedTest.artifacts = originalTest.artifacts ? [...originalTest.artifacts] : []
47+
const artifacts = originalTest.artifacts
48+
retriedTest.artifacts = artifacts ? (Array.isArray(artifacts) ? Object.assign([], artifacts) : { ...artifacts }) : []
4849
}
4950

5051
if (originalTest.steps !== undefined) {

lib/plugin/screencast.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ function buildSrt(steps) {
276276
}
277277

278278
function ensureArtifactsObject(test) {
279-
if (!test.artifacts || Array.isArray(test.artifacts)) test.artifacts = {}
279+
if (!test.artifacts) test.artifacts = {}
280+
else if (Array.isArray(test.artifacts)) test.artifacts = Object.assign({}, test.artifacts)
280281
}
281282

282283
function attachJUnitArtifact(test, filePath) {

test/unit/mocha/test_clone_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,34 @@ describe('Test cloning for retries', function () {
137137
expect(retriedTest.applyOptions).to.be.a('function')
138138
expect(retriedTest.simplify).to.be.a('function')
139139
})
140+
141+
it('should copy object-shaped artifacts on retry without throwing', function () {
142+
retryEnhancer()
143+
144+
const originalTest = createTest('Test with object artifacts', () => {})
145+
146+
originalTest.artifacts = { screenshot: 'failed.png', screencast: 'failed.webm' }
147+
148+
const retriedTest = Test.prototype.clone.call(originalTest)
149+
event.emit(event.test.before, retriedTest)
150+
151+
expect(retriedTest.artifacts).to.deep.equal({ screenshot: 'failed.png', screencast: 'failed.webm' })
152+
expect(retriedTest.simplify).to.be.a('function')
153+
})
154+
155+
it('should keep named keys written onto array-shaped artifacts', function () {
156+
retryEnhancer()
157+
158+
const originalTest = createTest('Test with mixed artifacts', () => {})
159+
160+
const artifacts = ['trace.zip']
161+
artifacts.screenshot = 'failed.png'
162+
originalTest.artifacts = artifacts
163+
164+
const retriedTest = Test.prototype.clone.call(originalTest)
165+
event.emit(event.test.before, retriedTest)
166+
167+
expect([...retriedTest.artifacts]).to.deep.equal(['trace.zip'])
168+
expect(retriedTest.artifacts.screenshot).to.equal('failed.png')
169+
})
140170
})

test/unit/plugin/screencast_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ describe('screencast', () => {
128128
expect(test.artifacts.screencast).to.match(/keep-on-fail.*\.webm$/)
129129
})
130130

131+
it('on=fail keeps a screenshot already written onto array-shaped artifacts', async () => {
132+
const sc = makeFakeScreencast()
133+
container.clear({ Playwright: { options: {}, page: { screencast: sc } } })
134+
135+
screencast({ on: 'fail' })
136+
const test = createTest('keep-screenshot')
137+
test.artifacts.screenshot = 'failed.png'
138+
139+
event.dispatcher.emit(event.test.before, test)
140+
event.dispatcher.emit(event.test.started, test)
141+
event.dispatcher.emit(event.step.started, aStep())
142+
await recorder.promise()
143+
144+
event.dispatcher.emit(event.test.failed, test, new Error('boom'))
145+
event.dispatcher.emit(event.test.after, test)
146+
await recorder.promise()
147+
148+
expect(test.artifacts.screenshot).to.equal('failed.png')
149+
expect(test.artifacts.screencast).to.match(/keep-screenshot.*\.webm$/)
150+
})
151+
131152
it('captions=true triggers showActions; captions=false does not', async () => {
132153
const sc = makeFakeScreencast()
133154
container.clear({ Playwright: { options: {}, page: { screencast: sc } } })

0 commit comments

Comments
 (0)