Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cypress 13 upgrade #3040

Merged
merged 46 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7200676
chore: upgrade and add needed cypress dependencies
jenniferarnesen Jul 24, 2024
ff89aaf
chore: move files to e2e and move to cypress.config.js
jenniferarnesen Jul 24, 2024
53940e6
chore: add cypress as a dev dependency
jenniferarnesen Jul 24, 2024
5b7662a
chore: add smoke test and disable some before fns for now
jenniferarnesen Jul 24, 2024
ab4e41f
chore: move cucumber config to own file
jenniferarnesen Jul 24, 2024
2ceac87
chore: use enableAutoLogin
jenniferarnesen Jul 24, 2024
cf11a01
chore: beforeEach running on everything and the offline tests are not…
jenniferarnesen Jul 24, 2024
cbf8806
chore: increase extended timeout
jenniferarnesen Jul 24, 2024
2ae06ec
chore: node version
jenniferarnesen Jul 24, 2024
cf0604f
chore: wrong test file path
jenniferarnesen Jul 24, 2024
9ea19ee
chore: cypress ci changes
jenniferarnesen Jul 24, 2024
2927f0c
chore: upgrade cypress-io/github-action
jenniferarnesen Jul 24, 2024
ef17af6
chore: username and password for ci
jenniferarnesen Jul 24, 2024
f2bcb0e
chore: need instance version
jenniferarnesen Jul 24, 2024
931cc35
chore: rename duplicate step
jenniferarnesen Jul 24, 2024
d233958
chore: another duplicated step
jenniferarnesen Jul 24, 2024
8951bdf
chore: syntax error
jenniferarnesen Jul 24, 2024
4211115
chore: rename duplicated steps
jenniferarnesen Jul 24, 2024
e4a75f7
chore: more duplicated steps
jenniferarnesen Jul 24, 2024
70a1871
chore: lint
jenniferarnesen Jul 24, 2024
3a4d4d8
chore: another duplicated step
jenniferarnesen Jul 25, 2024
f1c9419
chore: more duplicate steps
jenniferarnesen Jul 25, 2024
71af89d
chore: minor change to readme [e2e record]
jenniferarnesen Jul 25, 2024
1172ce7
chore: flatten test file structure
jenniferarnesen Jul 25, 2024
4d8483a
chore: more little errors in the tests
jenniferarnesen Jul 25, 2024
9c5ce56
chore: tweak trying to get tests to pass
jenniferarnesen Jul 25, 2024
1ff5f5b
chore: disable check for now
jenniferarnesen Jul 25, 2024
68bc9ee
chore: break up chain and wait
jenniferarnesen Jul 25, 2024
4f3b011
chore: disable test or checks that were previously disabled
jenniferarnesen Jul 25, 2024
af4ae11
chore: add FIXMEs back in
jenniferarnesen Jul 25, 2024
d44534f
chore: temp disable responsive tests
jenniferarnesen Jul 25, 2024
c6995c7
chore: re-enable 1 test
jenniferarnesen Jul 25, 2024
1de7b5f
chore: enable more steps
jenniferarnesen Jul 25, 2024
ee14f75
chore: try without all the cookie handling
jenniferarnesen Jul 25, 2024
ce49842
chore: restore
jenniferarnesen Jul 25, 2024
3729588
chore: enable rest of test
jenniferarnesen Jul 25, 2024
634d41f
chore: enable part of next resp test
jenniferarnesen Jul 26, 2024
33cc7ba
chore: enable rest of test
jenniferarnesen Jul 26, 2024
f34dfe4
chore: enable next test
jenniferarnesen Jul 26, 2024
442f680
chore: test tweak
jenniferarnesen Jul 26, 2024
1fb90a3
chore: enable more tests
jenniferarnesen Jul 26, 2024
51be6c0
chore: try enabling check on iframe
jenniferarnesen Jul 26, 2024
0523454
chore: purposely break test
jenniferarnesen Jul 26, 2024
4d69347
chore: unbreak test
jenniferarnesen Jul 29, 2024
2f32080
chore: try shared e2e workflow
jenniferarnesen Jul 30, 2024
b21333b
chore: remove commented code and unneeded devDep and update readme
jenniferarnesen Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .cypress-cucumber-preprocessorrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"nonGlobalStepDefinitions": true,
"e2e": {
"stepDefinitions": ["cypress/e2e/**/*.{js,ts}"]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/dhis2-preview-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 18.x

- uses: c-hive/gha-yarn-cache@v1
- run: yarn install --frozen-lockfile
Expand Down
151 changes: 85 additions & 66 deletions .github/workflows/dhis2-verify-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,76 +86,95 @@ jobs:
- name: Test
run: yarn d2-app-scripts test

e2e-prod:
runs-on: ubuntu-latest
needs: [test, setup-matrix]
call-workflow-e2e-prod:
if: "!contains(github.event.head_commit.message, '[skip ci]')"

strategy:
fail-fast: false
matrix:
spec-group: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}

env:
SHOULD_RECORD: ${{ contains(github.event.head_commit.message, '[e2e record]') || contains(join(github.event.pull_request.labels.*.name), 'e2e record') }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x

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

- name: Set Cypress Record Environment Variables
if: env.SHOULD_RECORD == 'true'
run: |
echo "CYPRESS_GROUP=e2e-${{ matrix.spec-group.id }}" >> $GITHUB_ENV
echo "CYPRESS_TAG=${{ github.event_name }}" >> $GITHUB_ENV
echo "CYPRESS_CI_BUILD_ID=${{ github.run_id }}" >> $GITHUB_ENV

- name: Debug Environment Variables
run: |
echo "SHOULD_RECORD=${{ env.SHOULD_RECORD }}"
echo "CI Build ID=${{ github.run_id }}"
echo "Computed Group=${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_GROUP || '' }}"
echo "Computed Tag=${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_TAG || '' }}"
echo "Computed CI Build ID=${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_CI_BUILD_ID || '' }}"
echo "Spec=${{ join(matrix.spec-group.tests, ',') }}"

- name: End-to-End tests
uses: cypress-io/github-action@v2
with:
start: ${{ env.SERVER_START_CMD }}
wait-on: ${{ env.SERVER_URL }}
wait-on-timeout: 300
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('patches/*.patch') }}
record: ${{ env.SHOULD_RECORD }}
parallel: ${{ env.SHOULD_RECORD }}
group: ${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_GROUP || '' }}
tag: ${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_TAG || '' }}
ci-build-id: ${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_CI_BUILD_ID || '' }}
spec: ${{ join(matrix.spec-group.tests, ',') }}
env:
CI: true
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
SERVER_START_CMD: 'yarn cypress:start'
SERVER_URL: 'http://localhost:3000'
cypress_dhis2_api_stub_mode: 'DISABLED'
REACT_APP_DHIS2_BASE_URL: ${{ secrets.CYPRESS_DHIS2_BASE_URL_41 }}
cypress_dhis2_base_url: ${{ secrets.CYPRESS_DHIS2_BASE_URL_41}}
cypress_dhis2_username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
cypress_dhis2_password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: [build, lint, test, setup-matrix]
uses: dhis2/workflows/.github/workflows/analytics-e2e-tests-prod.yml@master
with:
should_record: ${{ contains(github.event.head_commit.message, '[e2e record]') || contains(join(github.event.pull_request.labels.*.name), 'e2e record')}}
spec-group: ${{ needs.setup-matrix.outputs.matrix }}
secrets:
username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
recordkey: ${{ secrets.CYPRESS_RECORD_KEY }}
reportportal_api_key: ${{ secrets.REPORTPORTAL_API_KEY }}
reportportal_endpoint: ${{ vars.REPORTPORTAL_ENDPOINT }}
reportportal_project: ${{ vars.REPORTPORTAL_PROJECT }}

# e2e-prod:
# runs-on: ubuntu-latest
# needs: [test, setup-matrix]
# if: "!contains(github.event.head_commit.message, '[skip ci]')"

# strategy:
# fail-fast: false
# matrix:
# spec-group: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}

# env:
# SHOULD_RECORD: ${{ contains(github.event.head_commit.message, '[e2e record]') || contains(join(github.event.pull_request.labels.*.name), 'e2e record') }}

# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 18.x

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

# - name: Set Cypress Record Environment Variables
# if: env.SHOULD_RECORD == 'true'
# run: |
# echo "CYPRESS_GROUP=e2e-${{ matrix.spec-group.id }}" >> $GITHUB_ENV
# echo "CYPRESS_TAG=${{ github.event_name }}" >> $GITHUB_ENV
# echo "CYPRESS_CI_BUILD_ID=${{ github.run_id }}" >> $GITHUB_ENV

# - name: Debug Environment Variables
# run: |
# echo "SHOULD_RECORD=${{ env.SHOULD_RECORD }}"
# echo "CI Build ID=${{ github.run_id }}"
# echo "Computed Group=${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_GROUP || '' }}"
# echo "Computed Tag=${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_TAG || '' }}"
# echo "Computed CI Build ID=${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_CI_BUILD_ID || '' }}"
# echo "Spec=${{ join(matrix.spec-group.tests, ',') }}"

# - name: End-to-End tests
# uses: cypress-io/github-action@v5
# with:
# start: ${{ env.SERVER_START_CMD }}
# wait-on: ${{ env.SERVER_URL }}
# wait-on-timeout: 300
# cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('patches/*.patch') }}
# record: ${{ env.SHOULD_RECORD }}
# parallel: ${{ env.SHOULD_RECORD }}
# group: ${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_GROUP || '' }}
# tag: ${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_TAG || '' }}
# ci-build-id: ${{ env.SHOULD_RECORD == 'true' && env.CYPRESS_CI_BUILD_ID || '' }}
# spec: ${{ join(matrix.spec-group.tests, ',') }}
# env:
# CI: true
# CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
# SERVER_START_CMD: 'yarn cy:start'
# SERVER_URL: 'http://localhost:3000'
# cypress_dhis2_api_stub_mode: 'DISABLED'
# REACT_APP_DHIS2_BASE_URL: ${{ secrets.CYPRESS_DHIS2_BASE_URL_41 }}
# cypress_dhis2_base_url: ${{ secrets.CYPRESS_DHIS2_BASE_URL_41}}
# cypress_dhis2BaseUrl: ${{ secrets.CYPRESS_DHIS2_BASE_URL_41}}
# CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
# CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
# CYPRESS_dhis2InstanceVersion: '2.41'
# cypress_dhis2_username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
# cypress_dhis2_password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
runs-on: ubuntu-latest
needs: e2e-prod
needs: call-workflow-e2e-prod
if: |
!github.event.push.repository.fork &&
github.actor != 'dependabot[bot]' &&
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ REACT_APP_DHIS2_BASE_URL=http://localhost:8080

##### api authentication: REACT_APP_DHIS2_AUTHORIZATION

In order for maps, event reports and event charts to display in development mode, you also need to provide the authenticaion credentials for the api. The following example is the base64 encoded value for the username/password combination of `admin:district`:
In order for event reports and event charts to display in development mode, you also need to provide the authenticaion credentials for the api. The following example is the base64 encoded value for the username/password combination of `admin:district`:

```
REACT_APP_DHIS2_AUTHORIZATION=Basic YWRtaW46ZGlzdHJpY3Q=
Expand Down
3 changes: 0 additions & 3 deletions cypress-cucumber-preprocessor.config.js

This file was deleted.

53 changes: 53 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const {
addCucumberPreprocessorPlugin,
} = require('@badeball/cypress-cucumber-preprocessor')
const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild')
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor')
const { chromeAllowXSiteCookies } = require('@dhis2/cypress-plugins')
const { defineConfig } = require('cypress')

async function setupNodeEvents(on, config) {
await addCucumberPreprocessorPlugin(on, config)
chromeAllowXSiteCookies(on, config)

on(
'file:preprocessor',
createBundler({
plugins: [createEsbuildPlugin.default(config)],
})
)

return config
}

module.exports = defineConfig({
projectId: '5fk191',
chromeWebSecurity: false,
e2e: {
setupNodeEvents,
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/e2e/*.feature',
viewportWidth: 1280,
viewportHeight: 800,
defaultCommandTimeout: 45000,
/* Globally disable test isolation because the test suite
* contains many tests with sequential steps */
testIsolation: false,
// Record video
video: true,
// Enabled to reduce the risk of out-of-memory issues
experimentalMemoryManagement: true,
// Set to a low number to reduce the risk of out-of-memory issues
numTestsKeptInMemory: 5,
/* When allowing 1 retry on CI, the test suite will pass if
* it's flaky. And/but we also get to identify flaky tests on the
* Cypress Dashboard. */
retries: {
runMode: 1,
openMode: 0,
},
},
env: {
networkMode: 'live',
},
})
9 changes: 0 additions & 9 deletions cypress.json

This file was deleted.

18 changes: 18 additions & 0 deletions cypress/e2e/common/SL_dashboard_displays_in_view_mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Then } from '@badeball/cypress-cucumber-preprocessor'
import { dashboards } from '../../assets/backends/index.js'
// import { gridItemSel, chartSel } from '../../elements/dashboardItem.js'
import { dashboardTitleSel } from '../../elements/viewDashboard.js'
// import { EXTENDED_TIMEOUT } from '../../support/utils.js'

Then('the {string} dashboard displays in view mode', (title) => {
cy.location().should((loc) => {
expect(loc.hash).to.equal(dashboards[title].route)
})

cy.get(dashboardTitleSel).should('be.visible').and('contain', title)
// cy.get(gridItemSel)
// .first()
// .getIframeBody()
// .find(chartSel, EXTENDED_TIMEOUT)
// .should('exist')
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { When } from '@badeball/cypress-cucumber-preprocessor'
import {
unselectedItemsSel,
filterDimensionsPanelSel,
orgUnitTreeSel,
} from '../../../elements/dashboardFilter.js'
import { EXTENDED_TIMEOUT } from '../../../support/utils.js'
} from '../../elements/dashboardFilter.js'
import { EXTENDED_TIMEOUT } from '../../support/utils.js'

const PERIOD = 'Last 6 months'
const OU_ID = 'ImspTQPwCqd' //Sierra Leone
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { When } from '@badeball/cypress-cucumber-preprocessor'

When('dashboard items are added', () => {
cy.get('[data-test="item-search"]').click()
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/common/choose_to_delete_dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { clickEditActionButton } from '../../elements/editDashboard.js'

When('I choose to delete dashboard', () => {
clickEditActionButton('Delete')
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { When, Then } from 'cypress-cucumber-preprocessor/steps'
import { titleInputSel } from '../../../elements/editDashboard.js'
import { titleBarSel } from '../../../elements/viewDashboard.js'
import { EXTENDED_TIMEOUT } from '../../../support/utils.js'
import { When, Then } from '@badeball/cypress-cucumber-preprocessor'
import { titleInputSel } from '../../elements/editDashboard.js'
import { titleBarSel } from '../../elements/viewDashboard.js'
import { EXTENDED_TIMEOUT } from '../../support/utils.js'

const ROUTE_EDIT = 'edit'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { filterBadgeSel } from '../../../elements/dashboardFilter.js'
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { filterBadgeSel } from '../../elements/dashboardFilter.js'

When('I click on the {string} filter badge', (filterName) => {
cy.get(filterBadgeSel).find('span:visible').contains(filterName).click()
Expand Down
9 changes: 9 additions & 0 deletions cypress/e2e/common/close_item_selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { itemMenuSel } from '../../elements/editDashboard.js'

When('I close the item selector', () => {
//close modal
cy.get('[data-test="dhis2-uicore-layer"]').click('topLeft')

cy.get(itemMenuSel).should('not.exist')
})
6 changes: 6 additions & 0 deletions cypress/e2e/common/confirm_delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { confirmActionDialogSel } from '../../elements/editDashboard.js'

When('I confirm delete', () => {
cy.get(confirmActionDialogSel).find('button').contains('Delete').click()
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { confirmActionDialogSel } from '../../../elements/editDashboard.js'
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { confirmActionDialogSel } from '../../elements/editDashboard.js'

When('I confirm I want to discard changes', () => {
cy.get(confirmActionDialogSel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { dashboardTitleSel } from '../../../elements/viewDashboard.js'
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { dashboardTitleSel } from '../../elements/viewDashboard.js'

When('I click to exit print preview', () => {
cy.get('button').not('.small').contains('Exit print preview').click()
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/common/exit_without_saving.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { clickEditActionButton } from '../../elements/editDashboard.js'

When('I click Exit without saving', () => {
clickEditActionButton('Exit without saving')
})
14 changes: 14 additions & 0 deletions cypress/e2e/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import './before_each_visit_root.js'
import './add_dashboard_items.js'
import './confirm_discard_changes.js'
import './exit_without_saving.js'
import './add_a_FILTERTYPE_filter.js'
import './choose_to_edit_dashboard.js'
import './click_on_the_FILTERTYPE_filter_badge.js'
import './exit_print_layout.js'
import './open_print_layout.js'
import './open_the_SL_dashboard.js'
import './print_layout_displays.js'
import './start_new_dashboard.js'
import './the_dashboard_description_is_(not)_displayed.js'
import './SL_dashboard_displays_in_view_mode.js'
7 changes: 7 additions & 0 deletions cypress/e2e/common/message_dashboard_not_found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Then } from '@badeball/cypress-cucumber-preprocessor'
import { dashboardTitleSel } from '../../elements/viewDashboard.js'

Then('a message displays informing that the dashboard is not found', () => {
cy.contains('Requested dashboard not found').should('be.visible')
cy.get(dashboardTitleSel).should('not.exist')
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { clickViewActionButton } from '../../../elements/viewDashboard.js'
import { When } from '@badeball/cypress-cucumber-preprocessor'
import { clickViewActionButton } from '../../elements/viewDashboard.js'

When('I click to preview the print layout', () => {
clickViewActionButton('More')
Expand Down
Loading
Loading