@nrwl/cypress:cypress
Run Cypress for e2e, integration and component testing.
Options can be configured in project.json
when defining the executor, or when invoking it. Read more about how to configure targets and executors here: https://nx.dev/reference/project-configuration#targets.
Depending on your testing type, the Cypress executor is configured in different ways. The following are sample configurations that are created via the cypress-project and cypress-component-project generators.
1"targets": {
2 "e2e": {
3 "executor": "@nrwl/cypress:cypress",
4 "options": {
5 "cypressConfig": "apps/app-e2e/cypres.config.ts",
6 "devServerTarget": "my-react-app:serve",
7 "testingType": "e2e"
8 }
9 }
10}
11
API testing with Cypress is the same setup as e2e testing. Just change which devServerTarget
is used!
Providing a Base URL
If devServerTarget
is provided, the url returned from started the dev server will be passed to cypress as the baseUrl
option.
Defining a baseUrl
in the executor options will override the inferred baseUrl
from the devServerTarget
.
The baseUrl
defined in the Cypress config file is the last value used if no url is found in the devServerTarget
or executor options.
Static Serving
When running in CI it doesn't make sense to start up a dev server since there aren't changes to watch for.
You can use @nrwl/web:file-server
to serve the pre-built static files of your frontend project.
In some frontend application, add a 'static-serve' target.
1"serve-static": {
2 "executor": "@nrwl/web:file-server",
3 "options":{
4 "buildTarget": "frontend:build"
5 }
6}
7
In the e2e application add a configuration to change devServerTarget
to point to the static-serve
from the frontend application
1"e2e": {
2 //...
3 "configurations": {
4 "ci": {
5 "devServerTarget": "frontend:serve-static"
6 }
7 }
8}
9
The same can be done for backend node apps with @nrwl/js:node
executor
nx e2e my-app-e2e --configuration=ci
Environment Variables
Using executor configurations offers flexibility to set environment variables
1"targets": {
2 "e2e": {
3 "executor": "@nrwl/cypress:cypress",
4 "options": {
5 "cypressConfig": "apps/app-e2e/cypres.config.ts",
6 "devServerTarget": "my-react-app:serve",
7 "testingType": "e2e"
8 },
9 "configurations": {
10 "qa": {
11 "env": {
12 "API_URL": "https://api.qa.company.com"
13 }
14 },
15 "dev": {
16 "env": {
17 "API_URL": "http://locahost:3333/api"
18 }
19 }
20 }
21 }
22}
23
Read more on different ways to use environment variables for cypress executor