Skip to content

Commit

Permalink
chore: get cypress tests running
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 authored and edoardo committed Mar 30, 2023
1 parent 97434ea commit 82dc67d
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 14 deletions.
3 changes: 0 additions & 3 deletions cypress-cucumber-preprocessor.config.js

This file was deleted.

2 changes: 2 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const {
networkShim,
chromeAllowXSiteCookies,
cucumberPreprocessor,
} = require('@dhis2/cypress-plugins')
const { defineConfig } = require('cypress')

async function setupNodeEvents(on, config) {
await cucumberPreprocessor(on, config)
networkShim(on, config)
chromeAllowXSiteCookies(on, config)
return config
Expand Down
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 './edit/add_dashboard_items.js'
import './edit/confirm_discard_changes.js'
import './edit/exit_without_saving.js'
import './view/add_a_FILTERTYPE_filter.js'
import './view/choose_to_edit_dashboard.js'
import './view/click_on_the_FILTERTYPE_filter_badge.js'
import './view/exit_print_layout.js'
import './view/open_print_layout.js'
import './view/open_the_SL_dashboard.js'
import './view/print_layout_displays.js'
import './view/start_new_dashboard.js'
import './view/the_dashboard_description_is_(not)_displayed.js'
import './view/SL_dashboard_displays_in_view_mode.js'
1 change: 1 addition & 0 deletions cypress/e2e/edit/edit_dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/edit/edit_errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/edit/filter_restrict/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/view/dashboard_filter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/view/item_context_menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/view/offline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/view/responsive_dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/view/view_dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
1 change: 1 addition & 0 deletions cypress/e2e/view/view_errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../common/index.js'
11 changes: 7 additions & 4 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { enableAutoLogin } from '@dhis2/cypress-commands'
import { enableNetworkShim } from './server/index.js'
import { getDefaultMode, isStubMode } from './server/utils.js'
import { enableAutoLogin, enableNetworkShim, isStubMode, networkModes } from '@dhis2/cypress-commands'

const getDefaultMode = () => {
return networkModes.STUB
}

enableNetworkShim()

if (!isStubMode(getDefaultMode())) {
// log in if using a live backend
enableAutoLogin()
// High timeout as the app can take some time to load
enableAutoLogin(undefined, { timeout: 20000 })
}

const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Expand Down
4 changes: 2 additions & 2 deletions cypress/support/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
} from './constants.js'

export const getApiBaseUrl = () => {
const baseUrl = Cypress.env('dhis2_base_url') || ''
const baseUrl = Cypress.env('dhis2BaseUrl') || ''

if (!baseUrl) {
throw new Error(
'No `dhis2_base_url` found. Please make sure to add it to `cypress.env.json`'
'No `dhis2BaseUrl` found. Please make sure to add it to `cypress.env.json`'
)
}

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
"validate-push": "CI=true yarn test",
"postinstall": "patch-package",
"cypress:start": "BROWSER=none yarn start",
"cy:open-live": "yarn cypress open --env networkMode=live",
"cy:run-live": "cypress_dhis2_api_stub_mode=DISABLED d2-utils-cypress run --appStart 'yarn cypress:start'",
"cy:open-stub": "cypress_dhis2_api_stub_mode=STUB d2-utils-cypress open --appStart 'yarn cypress:start'",
"cy:run-stub": "cypress_dhis2_api_stub_mode=STUB d2-utils-cypress run --tags '@nonmutating' --appStart 'yarn cypress:start' --record",
"cy:capture": "cypress_dhis2_api_stub_mode=CAPTURE yarn d2-utils-cypress run --appStart 'yarn cypress:start'"
"cypress:open:live": "yarn cypress open --env networkMode=live",
"cypress:run:live": "yarn cypress run --env networkMode=live",
"cypress:run:capture": "yarn cypress run --env networkMode=capture",
"cypress:run:stub": "yarn cypress run --env networkMode=stub",
"cypress:prepare": "start-server-and-test 'yarn cypress:start' http://localhost:3000",
"cypress:live": "yarn cypress:prepare 'yarn cypress:open:live'",
"cypress:capture": "yarn cypress:prepare 'yarn cypress:run:capture'",
"cypress:stub": "yarn cypress:prepare 'yarn cypress:run:stub'"
},
"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "^16.0.0",
Expand Down

0 comments on commit 82dc67d

Please sign in to comment.