Skip to content

Commit

Permalink
chore: [TECH-1654] upgrade cypress to v12 (#3429)
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen authored Oct 26, 2023
1 parent b35f017 commit b1c1f1a
Show file tree
Hide file tree
Showing 98 changed files with 1,427 additions and 1,472 deletions.
2 changes: 1 addition & 1 deletion .cypress-cucumber-preprocessorrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"nonGlobalStepDefinitions": true
}
}
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REACT_APP_CACHE_VERSION=$npm_package_cacheVersion
REACT_APP_SERVER_VERSION=$npm_package_serverVersion
REACT_APP_VERSION=$npm_package_version
# TODO: Remove this when upgrading to react-scripts 5 (and webpack 5)
NODE_OPTIONS=--openssl-legacy-provider
10 changes: 5 additions & 5 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@ jobs:
needs: prerequisites
if: contains(fromJson(needs.prerequisites.outputs.json-labels), github.event.label.name)
runs-on: ubuntu-latest
container: cypress/browsers:node14.7.0-chrome84
strategy:
fail-fast: false
matrix:
versions: ${{ fromJSON(needs.prerequisites.outputs.versions) }}
containers: ${{ fromJSON(needs.prerequisites.outputs.matrix-containers) }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- name: compute-instance-url
id: instance-url
Expand All @@ -98,7 +97,7 @@ jobs:
version: ${{ matrix.versions }}

- name: Cypress run
uses: cypress-io/github-action@v4
uses: cypress-io/github-action@v6
with:
record: true
parallel: true
Expand All @@ -115,6 +114,7 @@ jobs:
CYPRESS_dhis2InstanceVersion: ${{matrix.versions}}
CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
NODE_OPTIONS: "--openssl-legacy-provider"

call-e2e-tests-result:
needs: cypress
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ on:
pull_request:
types: [ labeled ]

jobs:
jobs:
preview:
runs-on: ubuntu-latest
if: (github.event.label.name == 'preview' || github.event.label.name == 'testing') && !github.event.push.repository.fork && github.actor != 'dependabot[bot]'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
Expand Down
50 changes: 25 additions & 25 deletions .github/workflows/verify-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
Expand All @@ -40,10 +40,10 @@ jobs:
needs: install
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
Expand All @@ -59,10 +59,10 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
needs: install
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
Expand All @@ -78,10 +78,10 @@ jobs:
needs: install
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
Expand All @@ -91,7 +91,7 @@ jobs:

- name: Unit tests
run: yarn test

instance-version:
runs-on: ubuntu-latest
needs: [lint, flow, unit-tests]
Expand All @@ -105,11 +105,10 @@ jobs:
instance-url: ${{ secrets.CYPRESS_DHIS2_INSTANCES_BASE_URL }}/ca-test-dev
username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}

cypress-dev:
runs-on: ubuntu-latest
needs: instance-version
container: cypress/browsers:node14.7.0-chrome84
strategy:
# when one test fails, DO NOT cancel the other
# containers, because this will kill Cypress processes
Expand All @@ -119,13 +118,13 @@ jobs:
matrix:
containers: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- name: Cypress run
uses: cypress-io/github-action@v4
uses: cypress-io/github-action@v6
with:
record: true
parallel: true
Expand All @@ -142,16 +141,17 @@ jobs:
CYPRESS_dhis2InstanceVersion: ${{ needs.instance-version.outputs.version }}
CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
NODE_OPTIONS: "--openssl-legacy-provider"

build:
runs-on: ubuntu-latest
needs: [lint, flow, unit-tests]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/cache@v2
id: yarn-cache
Expand All @@ -175,13 +175,13 @@ jobs:
needs: build
if: "!github.event.push.repository.fork && !contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'dependabot[bot]'"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
token: ${{ env.GH_TOKEN }}

- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- uses: actions/download-artifact@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion config/eslint/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ if (fileExists(path.resolve(__dirname, '../../src/core_modules/capture-core')))
alias['capture-core-utils'] = path.resolve(__dirname, '../../src/core_modules/capture-core-utils');
}

module.exports = alias;
module.exports = alias;
35 changes: 35 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { chromeAllowXSiteCookies } = require('@dhis2/cypress-plugins');
const { defineConfig } = require('cypress');
const getCypressEnvVariables = require('./cypress/support/getCypressEnvVariables');
const cucumberPreprocessor = require('./cypress/support/cucumberPreprocessor');

async function setupNodeEvents(on, config) {
await chromeAllowXSiteCookies(on);
await cucumberPreprocessor(on, config);

config.env = getCypressEnvVariables(config);
return config;
}

module.exports = defineConfig({
video: true,
dhis2_datatest_prefix: 'dhis2-capture',
chromeWebSecurityComment:
'chromeWebSecurity should removed once https://github.com/cypress-io/cypress/issues/4220 is fixed',
chromeWebSecurity: false,
defaultCommandTimeout: 25000,
projectId: '322xnh',
experimentalFetchPolyfill: true,
retries: {
runMode: 3,
},
env: {
dhis2DataTestPrefix: 'capture-app',
networkMode: 'live',
},
e2e: {
setupNodeEvents,
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/e2e/**/*.feature',
},
});
18 changes: 0 additions & 18 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';

import '../sharedSteps';

Given('the user is on the the main page', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
import '../sharedSteps';

const showAllEventsInProgramStage = () => {
Expand Down Expand Up @@ -58,19 +59,6 @@ When(/^you click the checkbox number (.*)$/, (eq) => {
.click();
});

When(/^you click the (.*) button/, (buttonText) => {
cy.intercept({
method: 'POST',
url: '**/tracker?async=false',
}).as('postEvents');

cy.get('[data-test="dhis2-uicore-button"]')
.contains(buttonText)
.click();

cy.wait('@postEvents');
});

When(/^you click the button to (.*) without post request/, (buttonText) => {
cy.get('[data-test="dhis2-uicore-button"]')
.contains(buttonText)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Given, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import '../sharedSteps';

Given(/^you land on the enrollment (.*) page by having typed (.*)$/, (_, url) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';

Given('you land on the EnrollmentEventNew-page without a stageId', () => {
cy.visit('/#/enrollmentEventNew?programId=IpHINAT79UW&orgUnitId=DiszpKrYNg8&teiId=x2kJgpb0XQC&enrollmentId=RiNIt1yJoge');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';

Then(/^you see the following (.*)$/, (message) => {
cy.contains(message);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
import { getCurrentYear } from '../../../support/date';
import '../../sharedSteps';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Given, When, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';

Given(/^you land on the enrollment event page by having typed (.*)$/, (url) => {
cy.visit(url);
cy.get('[data-test="person-selector-container"]').contains('Person');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Feature: Breaking the glass page

# TODO - Flaky tests should be fixed by TECH-1662
@skip
Scenario: User with search scope access tries to access an enrollment in a protected program
Given the tei created by this test is cleared from the database
And you opt temporarily in on new enrollment dashboard in Child programme and WHO RMNCH Tracker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Given, When, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import '../sharedSteps';

Given('the tei created by this test is cleared from the database', () => {
Expand Down Expand Up @@ -89,6 +90,7 @@ And('you log out', () => {
});

And('you log in as tracker2 user', () => {
cy.clearCookies();
cy.visit('/').then(() => {
cy.get('#j_username').type('tracker2');
cy.get('#j_password').type('Tracker@123');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Given, When, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import '../../sharedSteps';

Given('you are on an enrollment page', () => {
Expand Down Expand Up @@ -105,10 +106,6 @@ When('you reset the tei selection', () => {
Then('you are navigated to the main page', () => {
cy.url().should('include', `${Cypress.config().baseUrl}/#/?orgUnitId=UgYg0YW7ZIh&programId=IpHINAT79UW`);
});
When('you reset the program selection', () => {
cy.get('[data-test="program-selector-container-clear-icon"]')
.click();
});

Then('you see message explaining you need to select a program', () => {
cy.url().should('not.include', 'programId');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';

Given('you are on an enrollment page with stage available', () => {
cy.visit('/#/enrollment?programId=ur1Edk5Oe2n&orgUnitId=UgYg0YW7ZIh&teiId=zmgVvEZ91Kg&enrollmentId=xRnBV5aJDeF');
cy.get('[data-test="enrollment-page-content"]')
Expand Down
Loading

0 comments on commit b1c1f1a

Please sign in to comment.