diff --git a/cypress.config.js b/cypress.config.js index 6ce2dc5d61..12810c2f08 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,3 +1,4 @@ +const fs = require('fs') const { chromeAllowXSiteCookies } = require('@dhis2/cypress-plugins') const { defineConfig } = require('cypress') const { @@ -8,6 +9,28 @@ async function setupNodeEvents(on, config) { chromeAllowXSiteCookies(on, config) excludeByVersionTags(on, config) + // Delete videos for passing tests + on('after:spec', (spec, results) => { + try { + if (results && results.video) { + // Do we have failures for any retry attempts? + const failures = results.tests.some((test) => + test.attempts.some((attempt) => attempt.state === 'failed') + ) + if (!failures) { + // delete the video if the spec passed and no tests retried + fs.unlinkSync(results.video) + } + } + } catch (error) { + if (error.code === 'ENOENT') { + console.log('Video already deleted') + } else { + throw error + } + } + }) + if (!config.env.dhis2InstanceVersion) { throw new Error( 'dhis2InstanceVersion is missing. Check the README for more information.' @@ -59,10 +82,6 @@ module.exports = defineConfig({ testIsolation: false, // Record video video: true, - /* Only compress and upload videos for failures. - * This will save execution time and reduce the risk - * out-of-memory issues on the CI machine */ - videoUploadOnPasses: false, // Enabled to reduce the risk of out-of-memory issues experimentalMemoryManagement: true, // Set to a low number to reduce the risk of out-of-memory issues