Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/listener/retryEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function copyCodeceptJSProperties(originalTest, retriedTest) {
}

if (originalTest.artifacts !== undefined) {
retriedTest.artifacts = originalTest.artifacts ? [...originalTest.artifacts] : []
const artifacts = originalTest.artifacts
retriedTest.artifacts = artifacts ? (Array.isArray(artifacts) ? Object.assign([], artifacts) : { ...artifacts }) : []
}

if (originalTest.steps !== undefined) {
Expand Down
3 changes: 2 additions & 1 deletion lib/plugin/screencast.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ function buildSrt(steps) {
}

function ensureArtifactsObject(test) {
if (!test.artifacts || Array.isArray(test.artifacts)) test.artifacts = {}
if (!test.artifacts) test.artifacts = {}
else if (Array.isArray(test.artifacts)) test.artifacts = Object.assign({}, test.artifacts)
}

function attachJUnitArtifact(test, filePath) {
Expand Down
30 changes: 30 additions & 0 deletions test/unit/mocha/test_clone_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,34 @@ describe('Test cloning for retries', function () {
expect(retriedTest.applyOptions).to.be.a('function')
expect(retriedTest.simplify).to.be.a('function')
})

it('should copy object-shaped artifacts on retry without throwing', function () {
retryEnhancer()

const originalTest = createTest('Test with object artifacts', () => {})

originalTest.artifacts = { screenshot: 'failed.png', screencast: 'failed.webm' }

const retriedTest = Test.prototype.clone.call(originalTest)
event.emit(event.test.before, retriedTest)

expect(retriedTest.artifacts).to.deep.equal({ screenshot: 'failed.png', screencast: 'failed.webm' })
expect(retriedTest.simplify).to.be.a('function')
})

it('should keep named keys written onto array-shaped artifacts', function () {
retryEnhancer()

const originalTest = createTest('Test with mixed artifacts', () => {})

const artifacts = ['trace.zip']
artifacts.screenshot = 'failed.png'
originalTest.artifacts = artifacts

const retriedTest = Test.prototype.clone.call(originalTest)
event.emit(event.test.before, retriedTest)

expect([...retriedTest.artifacts]).to.deep.equal(['trace.zip'])
expect(retriedTest.artifacts.screenshot).to.equal('failed.png')
})
})
21 changes: 21 additions & 0 deletions test/unit/plugin/screencast_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ describe('screencast', () => {
expect(test.artifacts.screencast).to.match(/keep-on-fail.*\.webm$/)
})

it('on=fail keeps a screenshot already written onto array-shaped artifacts', async () => {
const sc = makeFakeScreencast()
container.clear({ Playwright: { options: {}, page: { screencast: sc } } })

screencast({ on: 'fail' })
const test = createTest('keep-screenshot')
test.artifacts.screenshot = 'failed.png'

event.dispatcher.emit(event.test.before, test)
event.dispatcher.emit(event.test.started, test)
event.dispatcher.emit(event.step.started, aStep())
await recorder.promise()

event.dispatcher.emit(event.test.failed, test, new Error('boom'))
event.dispatcher.emit(event.test.after, test)
await recorder.promise()

expect(test.artifacts.screenshot).to.equal('failed.png')
expect(test.artifacts.screencast).to.match(/keep-screenshot.*\.webm$/)
})

it('captions=true triggers showActions; captions=false does not', async () => {
const sc = makeFakeScreencast()
container.clear({ Playwright: { options: {}, page: { screencast: sc } } })
Expand Down