Skip to content

Commit

Permalink
chore: setup cypress dependency & environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 committed Feb 7, 2023
1 parent fa583be commit 07aae64
Show file tree
Hide file tree
Showing 9 changed files with 1,438 additions and 62 deletions.
10 changes: 10 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"baseUrl": "http://localhost:3000",
"video": false,
"env": {
"dhis2DataTestPrefix": "dhis2-maintenance",
"networkMode": "live",
"dhis2ApiVersion": "40"
},
"experimentalInteractiveRunEvents": true
}
5 changes: 5 additions & 0 deletions cypress/integration/smoke_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Smoke test', () => {
it('should load the app without any errors', () => {
cy.visitAndLoad('/')
})
})
9 changes: 9 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {
networkShim,
chromeAllowXSiteCookies,
} = require('@dhis2/cypress-plugins')

module.exports = (on, config) => {
networkShim(on)
chromeAllowXSiteCookies(on)
}
5 changes: 5 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { enableAutoLogin, enableNetworkShim } from '@dhis2/cypress-commands'
import './visit-and-load.js'

enableAutoLogin()
enableNetworkShim()
4 changes: 4 additions & 0 deletions cypress/support/visit-and-load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Cypress.Commands.add('visitAndLoad', (...args) => {
cy.visit(...args)
cy.get('.selector-bar-item').should('exist')
})
1 change: 1 addition & 0 deletions docs/developer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ has yet to be explored by the entire team).

## Specific topics

* [Setting up & running cypress tests](./cypress-tests.md)
* [Folder structure](./folder-structure.md)
* [Url path structure](./url-path-structure.md)
* [Client-side state](./client-side-state.md)
Expand Down
45 changes: 45 additions & 0 deletions docs/developer/cypress-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Setting up & running cypress tests

## Prerequisites

In order to run cypress tests, a `cypress.env.json` is required in the root
directory. This file is ignored by git on purpose so we don't end up storing
credentials in the public repository.

The file has to look like this:

```json
{
"dhis2BaseUrl": "https://debug.dhis2.org/dev",
"dhis2Username": "system",
"dhis2Password": "System123"
}
```

## Working on cypress tests

The easiest way to work on cypress tests is by starting the app's start script
and the cypress open script independently. There are situations where the
cypress UI has to be restarted and it's more convenient to not have to wait for
the UI as well:

* In one terminal, run `yarn cypress:start`
* In another terminal, run `yarn cypress:open:live`

### Checking whether capturing & stubbing requests work

As this can be a time consuming task, similarly to working on cypress tests,
there are scripts that expect the app to be running already instead of starting
it as well:

* `yarn cypress:run:capture`: Will run the tests and record all network
requests
* `yarn cypress:run:stub`: Will run the tests and use the recorded requests

## Capturing & replaying network requests

When done working on a branch, you can:

* run `yarn cypress:capture` to generate network fixtures
* run `yarn cypress:stub` to test whether the app works with the generated
fixtures
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@
"scripts": {
"build": "d2-app-scripts build",
"start": "d2-app-scripts start",
"start:nobrowser": "BROWSER=none yarn start",
"test": "d2-app-scripts test",
"deploy": "d2-app-scripts deploy"
"deploy": "d2-app-scripts deploy",
"cy": "NODE_OPTIONS=--openssl-legacy-provider yarn cypress",
"cypress:start": "REACT_APP_NODE_ENV=test yarn start:nobrowser",
"cypress:open:live": "yarn cy open --env networkMode=live",
"cypress:prepare": "start-server-and-test 'yarn cypress:start' http://localhost:3000",
"cypress:run:live": "yarn cy run --env networkMode=live",
"cypress:live": "yarn cypress:prepare 'yarn cypress:open:live'",
"cypress:run:capture": "yarn cy run --env networkMode=capture",
"cypress:capture": "yarn cypress:prepare 'yarn cypress:run:capture'",
"cypress:run:stub": "yarn cy run --env networkMode=stub",
"cypress:stub": "yarn cypress:prepare 'yarn cypress:run:stub'"
},
"devDependencies": {
"@dhis2/cli-app-scripts": "^10.2.0"
"@dhis2/cli-app-scripts": "^10.2.0",
"@dhis2/cypress-commands": "^9.0.2",
"@dhis2/cypress-plugins": "^9.0.2",
"cypress": "^9",
"start-server-and-test": "^1.15.3"
},
"dependencies": {
"@dhis2/app-runtime": "^3.8.0",
Expand Down
Loading

0 comments on commit 07aae64

Please sign in to comment.