Skip to content

Commit

Permalink
Add skip test mechanism back
Browse files Browse the repository at this point in the history
  • Loading branch information
rh-gvincent committed May 17, 2023
1 parent a4604df commit 0005848
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libs/integration-tests-ocm/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ module.exports = defineConfig({
ASSISTED_MINIMAL_ISO: false,
},
e2e: {
setupNodeEvents(on, config) {},
setupNodeEvents(on, config) {
return require('./src/plugins/index.ts')(on, config);
},
specPattern: './src/integration/**/*.cy.{js,jsx,ts,tsx}',
supportFile: './src/support/index.ts',
baseUrl: 'http://localhost:4173',
Expand Down
53 changes: 53 additions & 0 deletions libs/integration-tests-ocm/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

let shouldSkip = false;

module.exports = (on) => {
on('task', {
resetShouldSkipFlag() {
shouldSkip = false;
return null;
},
shouldSkip(value) {
// From the moment a test fails, set the skip flag to true for all remaining tests
if (value === true) {
shouldSkip = value;
}
return shouldSkip;
},
});
on('before:browser:launch', (browser, options) => {
// only Firefox requires all mime types to be listed
if (browser.family === 'firefox') {
const existingMimeTypes = options.preferences['browser.helperApps.neverAsk.saveToDisk'];
// PSI reports 'application/octet-stream' as mime
// AWS reports 'binary/octet-stream' as mime
const myMimeType = 'application/octet-stream,binary/octet-stream';

// prevents the browser download prompt
options.preferences[
'browser.helperApps.neverAsk.saveToDisk'
] = `${existingMimeTypes},${myMimeType}`;
options.preferences[
'browser.helperApps.neverAsk.openFile'
] = `${existingMimeTypes},${myMimeType}`;
options.preferences['browser.helperApps.alwaysAsk.force'] = false;
options.preferences['browser.download.manager.useWindow'] = false;
options.preferences['browser.download.folderList'] = 1;
options.preferences['browser.download.manager.showWhenStarting'] = false;
options.preferences['browser.download.manager.focusWhenStarting'] = false;
options.preferences['browser.download.manager.showAlertOnComplete'] = false;
options.preferences['browser.download.manager.closeWhenDone'] = false;
}
return options;
});
};
23 changes: 23 additions & 0 deletions libs/integration-tests-ocm/src/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,27 @@ import './selectors';
import './variables/index';
import * as utils from './utils';

// eslint-disable-next-line consistent-return
function abortEarly() {
if (this.currentTest.state === 'failed') {
return cy.task('shouldSkip', true);
}
cy.task('shouldSkip').then((value) => {
if (value) this.skip();
});
}

beforeEach(abortEarly);
afterEach(abortEarly);

before(() => {
if (Cypress.browser.isHeaded) {
// Reset the shouldSkip flag at the start of a run, so that it
// doesn't carry over into subsequent runs.
// Do this only for headed runs because in headless runs,
// the `before` hook is executed for each spec file.
cy.task('resetShouldSkipFlag');
}
});

export { utils };

0 comments on commit 0005848

Please sign in to comment.