Skip to content

Instantly share code, notes, and snippets.

@agoldis
Created January 19, 2023 18:38
Show Gist options
  • Save agoldis/671141a08f0fbd010b1cec1a1d093c2b to your computer and use it in GitHub Desktop.
Save agoldis/671141a08f0fbd010b1cec1a1d093c2b to your computer and use it in GitHub Desktop.
Record videos only for failed or flaky tests
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