diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index cb207cd6f..7045ae0f0 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -4,61 +4,61 @@ import './commands.js' enableAutoLogin() -// // const LOGIN_ENDPOINT = 'dhis-web-commons-security/login.action' -// const SESSION_COOKIE_NAME = 'JSESSIONID' -// const LOCAL_STORAGE_KEY = 'DHIS2_BASE_URL' +// const LOGIN_ENDPOINT = 'dhis-web-commons-security/login.action' +const SESSION_COOKIE_NAME = 'JSESSIONID' +const LOCAL_STORAGE_KEY = 'DHIS2_BASE_URL' -// // '2.39' or 39? -// const computeEnvVariableName = (instanceVersion) => -// typeof instanceVersion === 'number' -// ? `${SESSION_COOKIE_NAME}_${instanceVersion}` -// : `${SESSION_COOKIE_NAME}_${instanceVersion.split('.').pop()}` +// '2.39' or 39? +const computeEnvVariableName = (instanceVersion) => + typeof instanceVersion === 'number' + ? `${SESSION_COOKIE_NAME}_${instanceVersion}` + : `${SESSION_COOKIE_NAME}_${instanceVersion.split('.').pop()}` -// const findSessionCookieForBaseUrl = (baseUrl, cookies) => -// cookies.find( -// (cookie) => -// cookie.name === SESSION_COOKIE_NAME && baseUrl.includes(cookie.path) -// ) +const findSessionCookieForBaseUrl = (baseUrl, cookies) => + cookies.find( + (cookie) => + cookie.name === SESSION_COOKIE_NAME && baseUrl.includes(cookie.path) + ) -// const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/ -// Cypress.on('uncaught:exception', (err) => { -// /* returning false here prevents Cypress from failing the test */ -// if (resizeObserverLoopErrRe.test(err.message)) { -// return false -// } -// }) +const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/ +Cypress.on('uncaught:exception', (err) => { + /* returning false here prevents Cypress from failing the test */ + if (resizeObserverLoopErrRe.test(err.message)) { + return false + } +}) -// before(() => { -// const baseUrl = Cypress.env('dhis2BaseUrl') -// const instanceVersion = Cypress.env('dhis2InstanceVersion') +before(() => { + const baseUrl = Cypress.env('dhis2BaseUrl') + const instanceVersion = Cypress.env('dhis2InstanceVersion') -// cy.getAllCookies() -// .should((cookies) => { -// expect(cookies.length).to.be.at.least(1) -// }) -// .then((cookies) => { -// const sessionCookieForBaseUrl = findSessionCookieForBaseUrl( -// baseUrl, -// cookies -// ) -// Cypress.env( -// computeEnvVariableName(instanceVersion), -// JSON.stringify(sessionCookieForBaseUrl) -// ) -// }) -// }) + cy.getAllCookies() + .should((cookies) => { + expect(cookies.length).to.be.at.least(1) + }) + .then((cookies) => { + const sessionCookieForBaseUrl = findSessionCookieForBaseUrl( + baseUrl, + cookies + ) + Cypress.env( + computeEnvVariableName(instanceVersion), + JSON.stringify(sessionCookieForBaseUrl) + ) + }) +}) -// beforeEach(() => { -// const baseUrl = Cypress.env('dhis2BaseUrl') -// const instanceVersion = Cypress.env('dhis2InstanceVersion') -// const envVariableName = computeEnvVariableName(instanceVersion) -// const { name, value, ...options } = JSON.parse(Cypress.env(envVariableName)) +beforeEach(() => { + const baseUrl = Cypress.env('dhis2BaseUrl') + const instanceVersion = Cypress.env('dhis2InstanceVersion') + const envVariableName = computeEnvVariableName(instanceVersion) + const { name, value, ...options } = JSON.parse(Cypress.env(envVariableName)) -// localStorage.setItem(LOCAL_STORAGE_KEY, baseUrl) -// cy.setCookie(name, value, options) + localStorage.setItem(LOCAL_STORAGE_KEY, baseUrl) + cy.setCookie(name, value, options) -// cy.getAllCookies().should((cookies) => { -// expect(findSessionCookieForBaseUrl(baseUrl, cookies)).to.exist -// expect(localStorage.getItem(LOCAL_STORAGE_KEY)).to.equal(baseUrl) -// }) -// }) + cy.getAllCookies().should((cookies) => { + expect(findSessionCookieForBaseUrl(baseUrl, cookies)).to.exist + expect(localStorage.getItem(LOCAL_STORAGE_KEY)).to.equal(baseUrl) + }) +})