Skipping Cypress tests on first failure and save resources in CI-CD

Cypress tree
afterEach(function onAfterEach() {
if (this.currentTest.state === ‘failed’) {
cy.setCookie(‘shouldSkip’, ‘true’);
//set cookie to skip tests for further specs
Cypress.runner.stop();
//this will skip tests only for current spec
}
});
before(() => {
if ( Cypress.browser.isHeaded ) {
cy.clearCookie('shouldSkip')
} else {
cy.getCookie('shouldSkip').then(cookie => {
if (
cookie &&
typeof cookie === 'object' &&
cookie.value === 'true'
) {
Cypress.runner.stop();
}
});
}
});
Cypress.Cookies.defaults({
whitelist: 'shouldSkip',
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store