From a9ecce2394619b3aea1c56bef2ff357ab585ef3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Dubigny?= Date: Tue, 21 May 2024 15:21:46 +0200 Subject: [PATCH] chore: add option to record tests with cypress to generate demo videos --- cypress.config.js | 3 +++ cypress/support/e2e.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/cypress.config.js b/cypress.config.js index 16183b66..ea2953eb 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,3 +1,5 @@ +const RECORD = process.env.CYPRESS_RECORD === "true"; + export default { chromeWebSecurity: false, defaultCommandTimeout: 60000, @@ -17,4 +19,5 @@ export default { return config; }, }, + video: RECORD, }; diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 02cdf907..78240e21 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -37,3 +37,31 @@ Cypress.Commands.add("login", (email, password) => { .click(); }); }); + +const RECORD = Cypress.env("RECORD") === true; + +if (RECORD) { + for (const command of [ + "visit", + "click", + "trigger", + "type", + "clear", + "reload", + ]) { + Cypress.Commands.overwrite(command, (originalFn, ...args) => { + const origVal = originalFn(...args); + + return new Promise((resolve) => { + setTimeout( + () => { + resolve(origVal); + }, + RECORD ? 2000 : 0, + ); + }); + }); + } + Cypress.config("viewportWidth", 2560); + Cypress.config("viewportHeight", 1440); +}