From bb010b233b98988a95acb022ed7232704243f398 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Thu, 6 Feb 2025 18:40:40 +0100 Subject: [PATCH] test: Expose set and getVariable in Cypress tests Partial cherry pick of 4a90d5328 Signed-off-by: Louis Chemineau --- cypress.config.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cypress.config.ts b/cypress.config.ts index 98ea63758cc..1e83c0b7f5d 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -68,6 +68,19 @@ export default defineConfig({ on('task', { removeDirectory }) + // This allows to store global data (e.g. the name of a snapshot) + // because Cypress.env() and other options are local to the current spec file. + const data = {} + on('task', { + setVariable({ key, value }) { + data[key] = value + return null + }, + getVariable({ key }) { + return data[key] ?? null + }, + }) + // Disable spell checking to prevent rendering differences on('before:browser:launch', (browser, launchOptions) => { if (browser.family === 'chromium' && browser.name !== 'electron') {