Functional Testing with Cypress
Cypress support has moved into NX. See NX - Frontend Testing for more information!
Cypress: Functional tests
We are using Cypress for functional testing as much as possible. The key features of Cypress:
- Integration testing with API testing support (Node.js)
- Easy to debug
- Selector playground
- Great documentation
- Best implementation of Live Reloading
Why Cypress is categorised in the pre-deployed tests
The Cypress tests, if structured correctly, can be run BEFORE the app client is deployed to an environment. This is to ensure that we get the fastest feedback we can. If you are following branching strategies such as GitFlow, then you can run these tests on your branch before merging to master.
BENEFITS | DOWNSIDES |
---|---|
deployment independent | not full integration tests as not running on deployed infrastructure |
faster feedback | |
run core tests before the branch is merged to master, smoke tests post-merge and deployment |
How Cypress is run in Continuous Integration (CI) pipelines
Glad you asked. You'll see an npm script in the package.json
which uses start-server-and-test. This package starts the Node.js Express server, waits for the app URL (localhost in this case), then runs test command; when the tests end, it shuts down the server instance.
Key benefits means we never have to explicitly wait for the server to be ready before testing.
package.json script:
"test:cypress" : "env CI=true node_modules/.bin/start-server-and-test start $APP_BASE_URL:$PORT test:cypress:run"