Skip to content

Commit

Permalink
Upgrade Cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsomthd committed Nov 12, 2024
1 parent e48ccb0 commit 29ff638
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 153 deletions.
1 change: 1 addition & 0 deletions cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
setupNodeEvents,
specPattern: 'cypress/tests/**/*.ts',
supportFile: 'cypress/support.ts',
testIsolation: false,
},
fixturesFolder: false,
reporter: 'node_modules/cypress-multi-reporters',
Expand Down
14 changes: 10 additions & 4 deletions cypress/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import {
import './support/selectors';
import './support/login';

before(() => {
// Disable Cypress's default behavior of logging all XMLHttpRequests and fetches.
cy.intercept({ resourceType: /xhr|fetch/ }, { log: false });
});

beforeEach(() => {
// Disable Cypress's default behavior of logging all XMLHttpRequests and fetches.
cy.intercept({ resourceType: /xhr|fetch/ }, { log: false });
});

declare global {
namespace Cypress {
interface Chainable {
Expand All @@ -23,10 +33,6 @@ Cypress.on('uncaught:exception', () => {

Cypress.Cookies.debug(true);

Cypress.Cookies.defaults({
preserve: ['openshift-session-token', 'csrf-token'],
});

Cypress.Commands.add('install', () => {
cy.exec(
`oc get storagesystem ${STORAGE_SYSTEM_NAME} -n ${CLUSTER_NAMESPACE}`,
Expand Down
67 changes: 37 additions & 30 deletions cypress/support/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,44 @@ declare global {
Cypress.Commands.add(
'login',
(provider: string, username: string, password: string) => {
// Check if auth is disabled (for a local development environment).
cy.visit(''); // visits baseUrl which is set in plugins.js
cy.window().then((win: any) => {
if (win.SERVER_FLAGS?.authDisabled) {
cy.task(
'log',
' skipping login, console is running with auth disabled'
);
return;
}
// Make sure we clear the cookie in case a previous test failed to logout.
cy.clearCookie('openshift-session-token');
cy.session(
'user-session',
() => {
// Check if auth is disabled (for a local development environment).
cy.visit(''); // visits baseUrl which is set in plugins.js
cy.window().then((win: any) => {
if (win.SERVER_FLAGS?.authDisabled) {
cy.task(
'log',
' skipping login, console is running with auth disabled'
);
return;
}

const idp = provider || KUBEADMIN_IDP;
cy.task('log', ` Logging in as ${username || KUBEADMIN_USERNAME}`);
cy.byLegacyTestID('login').should('be.visible');
// eslint-disable-next-line cypress/require-data-selectors
cy.get('body').then(($body) => {
if ($body.text().includes(idp)) {
cy.contains(idp).should('be.visible').click();
}
});
/* eslint-disable cypress/require-data-selectors */
cy.get('#inputUsername').type(username || KUBEADMIN_USERNAME);
cy.get('#inputPassword').type(
password || Cypress.env('BRIDGE_KUBEADMIN_PASSWORD')
);
cy.get(submitButton).click();
/* eslint-enable cypress/require-data-selectors */
masthead.username.shouldBeVisible();
});
const idp = provider || KUBEADMIN_IDP;
cy.task('log', ` Logging in as ${username || KUBEADMIN_USERNAME}`);
cy.byLegacyTestID('login').should('be.visible');
// eslint-disable-next-line cypress/require-data-selectors
cy.get('body').then(($body) => {
if ($body.text().includes(idp)) {
cy.contains(idp).should('be.visible').click();
}
});
/* eslint-disable cypress/require-data-selectors */
cy.get('#inputUsername').type(username || KUBEADMIN_USERNAME);
cy.get('#inputPassword').type(
password || Cypress.env('BRIDGE_KUBEADMIN_PASSWORD'),
{
log: false,
}
);
cy.get(submitButton).click();
/* eslint-enable cypress/require-data-selectors */
masthead.username.shouldBeVisible();
});
},
{ cacheAcrossSpecs: true }
);
}
);

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"yup": "^0.32.11"
},
"devDependencies": {
"@cypress/webpack-preprocessor": "^5.9.1",
"@cypress/webpack-preprocessor": "^6.0.2",
"@discoveryjs/json-ext": "0.6.1",
"@swc/core": "1.3.19",
"@swc/jest": "^0.2.23",
Expand All @@ -147,8 +147,8 @@
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"comment-json": "4.x",
"cypress": "^10.10.0",
"cypress-multi-reporters": "^1.5.0",
"cypress": "^13.15.2",
"cypress-multi-reporters": "^2.0.4",
"eslint": "^8.57.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
Expand Down
Loading

0 comments on commit 29ff638

Please sign in to comment.