no-record-video-test-passed-cypress-plugin
Version:
Plugin delete the recorded video for specs that had no retry attempts or failures when using Cypress test retries.
42 lines (37 loc) • 1.17 kB
JavaScript
const fs = require("fs");
const logger = require("./logger");
function getPluginConfig(config, reportError) {
if (
Object.keys(config).includes("env") &&
Object.keys(config.env).includes("noRecordVideoTestPassed") &&
!!config.env.noRecordVideoTestPassed.enable
) {
return config.env.noRecordVideoTestPassed;
} else {
if (!!reportError)
logger.error(
"No Record Video plugin is disabled. Please set env:{noRecordVideoTestPassed:{enable:true}}",
true
);
}
}
const noRecordVideoTestPassed = (on, config) => {
on("before:run", () => {
let pluginConfig = getPluginConfig(config, true);
});
on("after:spec", (spec, results) => {
let pluginConfig = getPluginConfig(config);
if (pluginConfig.enable) {
if (results && results.video) {
const failures = results.tests.some((test) =>
test.attempts.some((attempt) => attempt.state === "failed")
);
if (!failures) {
logger.log("No Record Video plugin remove video for passed test !");
fs.unlinkSync(results.video);
}
}
}
});
};
module.exports = { noRecordVideoTestPassed };