Search…
Workspace Settings
Various project settings can be controlled from the workspace.json file, located in the root of the repository.

E2E Testing Configuration

The default Nx setup for E2E tests is experiencing timeouts during some of our tests. This is due to long build and compile time of NextJS apps. In effort to optimize this process we have created an e2e-ci.js script in the scripts/ directory. It starts by creating a production build of the app under testing, before starting the Cypress tests. Following is a documentation of the configuration needed to enable the e2e-ci task.

Pre-requisites

Setting API_MOCKS

NextJS
We need to make sure that the API_MOCKS environment variable is set in the next.config.js
1
// ...
2
serverRuntimeConfig: {
3
// ...
4
},
5
publicRuntimeConfig: {
6
// ...
7
},
8
env: {
9
API_MOCKS: process.env.API_MOCKS,
10
},
Copied!
React
For React apps we have a common webpack config in libs/share/webpack which we use to make sure the API_MOCKS environment variable is set, along with other common plugins and settings.
Your webpack.config.js should look like this:
1
// eslint-disable-next-line @typescript-eslint/no-var-requires
2
const nrwlConfig = require('./../../libs/shared/webpack/nrwl-config')
3
4
module.exports = (config, context) => {
5
// Add our common webpack config
6
nrwlConfig(config)
7
8
// Here you can add app specific config
9
10
return config
11
}
Copied!

devServerTarget and Cypress baseUrl

We need to set the devServerTarget for the production config of the e2e task for the corresponding e2e project.
We also need to let Cypress now what the baseUrl of our app is (as we are running it manually). That is done by adding baseUrl to the options key of the e2e task.
See the following example for the web project:
1
"e2e": {
2
"builder": "@nrwl/cypress:cypress",
3
"options": {
4
"cypressConfig": "apps/web-e2e/cypress.json",
5
"tsConfig": "apps/web-e2e/tsconfig.e2e.json",
6
"baseUrl": "http://localhost:4200",
7
"devServerTarget": "web:serve"
8
},
9
"configurations": {
10
"production": {
11
"devServerTarget": ""
12
}
13
}
14
},
Copied!

Add e2e-ci task

Finally we need to add a e2e-ci task to the architect property of the corrensponding e2e project.

NextJS

1
"e2e-ci": {
2
"builder": "@nrwl/workspace:run-commands",
3
"options": {
4
"command": "yarn e2e-ci -n web-e2e -d dist/apps/web"
5
}
6
},
Copied!

React

1
"e2e-ci": {
2
"builder": "@nrwl/workspace:run-commands",
3
"options": {
4
"command": "yarn e2e-ci -n service-portal-e2e -t react -f dist/apps/service-portal -b /minarsidur"
5
}
6
},
Copied!

Configure

The e2e-ci.js script requires few parameters:
  • -n - Required. The name of the e2e project. The script uses this name to find
    the name of the target app (by stripping of the -e2e ending).
  • -d - Required. Sets the output directory for the production build.
  • -s - Boolean to indicate if to use --skip-nx-cache
  • -t - Only for React. Sets the app type to react.
  • -b - Optional for React. If the app is deployed to a sub-directory,
    that is the base in index.html this option is needed to
    set that path.
Further details can be found be using the -h parameter for the script:
1
node scripts/e2e-ci.js -h
Copied!

E2E test locally

To test e2e locally it can either be done like before using the e2etask
1
yarn e2e web-e2e
Copied!
or using the e2e-ci task
1
yarn nx run web-e2e:e2e-ci
Copied!

E2E in CI

This task is executed as part of our GitHub CI pipeline via the 40_e2e.sh. This script adds the -c option to enable Cypress recording.
Last modified 9mo ago