Created
January 19, 2023 18:38
-
-
Save agoldis/671141a08f0fbd010b1cec1a1d093c2b to your computer and use it in GitHub Desktop.
Record videos only for failed or flaky tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { defineConfig } = require("cypress"); | |
const fs = require("fs"); | |
module.exports = defineConfig({ | |
video: true, | |
videoUploadOnPasses: true, | |
e2e: { | |
baseUrl: "https://en.wikipedia.org/", | |
specPattern: "cypress/integration/*.spec.js", | |
supportFile: "cypress/support/e2e.js", | |
setupNodeEvents(on, config) { | |
on("after:spec", (spec, results) => { | |
console.log("after:spec", spec, results.video); | |
if (results && results.video) { | |
// Do we have failures for any retry attempts? | |
const failures = results.tests?.some((test) => | |
test.attempts?.some(({ state }) => state == "failed") | |
); | |
// Delete the video if there are no failures | |
if (!failures) { | |
try { | |
return fs.unlinkSync(results.video); | |
} catch (e) {} | |
} | |
} | |
}); | |
}, | |
}, | |
projectId: "xxx", | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment