Skip to content

Commit 1e2f194

Browse files
Merge pull request #2473 from cfpb/2472-only-save-failing-test-runs
## Changes - delete videos that don't contain a test failure, as [per the docs](https://docs.cypress.io/app/guides/screenshots-and-videos#Delete-videos-for-specs-without-failing-or-retried-tests) ## Testing 1. Does the test suite run normally? 2. Do tests that pass not have saved videos? ![Screenshot 2025-04-07 at 6 05 00 PM](https://github.com/user-attachments/assets/de1f5eb2-8b07-497f-9701-96a36a97e9bf) 3. Do tests that fail still have saved videos? ![Screenshot 2025-04-07 at 6 07 28 PM](https://github.com/user-attachments/assets/25973d4c-0f31-45fd-98f5-6d9f0028c322) Closes: #2472
2 parents c1a8804 + 1701e10 commit 1e2f194

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cypress.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { defineConfig } = require('cypress')
2+
const fs = require('fs')
23

34
module.exports = defineConfig({
45
chromeWebSecurity: false,
@@ -41,6 +42,24 @@ module.exports = defineConfig({
4142
runMode: 2,
4243
openMode: 0
4344
},
45+
// Delete videos for specs without failing or retried tests, see docs:
46+
// https://docs.cypress.io/app/guides/screenshots-and-videos#Delete-videos-for-specs-without-failing-or-retried-tests
47+
setupNodeEvents(on, config) {
48+
on('after:spec', (spec, results) => {
49+
if (results && results.video) {
50+
// Do we have failures for any retry attempts?
51+
const failures = results.tests.some((test) =>
52+
test.attempts.some((attempt) => attempt.state === 'failed')
53+
)
54+
// Check to make sure the video file exists before deleting, see https://stackoverflow.com/a/76113045
55+
if (!failures && fs.existsSync(results.video)) {
56+
// delete the video if the spec passed and no tests retried
57+
fs.unlinkSync(results.video)
58+
console.log(`All tests passed, deleting video file: ${results.video}`)
59+
}
60+
}
61+
})
62+
},
4463
},
4564

4665
component: {

0 commit comments

Comments
 (0)