-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1901 from TouK/cypress-documentation
Cypress (and FE in general) documentation improvement
- Loading branch information
Showing
5 changed files
with
141 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ _book/ | |
out/ | ||
*.bsp | ||
ui/client/cypress/fixtures/env.json | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,134 @@ | ||
# Prerequisites | ||
|
||
## NodeJS and NPM | ||
|
||
Make sure you have relatively new nodejs/npm version (see `.nvmrc` for details) | ||
|
||
## Package dependencies | ||
|
||
Fetch locked package dependencies using: | ||
``` | ||
npm ci | ||
``` | ||
|
||
# Run | ||
|
||
You have a few options to provide backend for frontend needs. After each "run" command, frontend will be available at http://localhost:3000. | ||
Below there are described possible options. | ||
|
||
## Using backend started with docker | ||
|
||
This option requires docker and connection to docker hub registry. It will use `touk/nussknacker` image in `staging-latest` version. | ||
``` | ||
npm run start:backend-staging | ||
``` | ||
|
||
## Using locally started backend | ||
|
||
This option uses backend started at http://localhost:8080 . For more information how to start it, take a look at [Backend instruction](../README.md) | ||
``` | ||
npm ci && npm start | ||
open http://localhost:3000 | ||
npm start | ||
``` | ||
|
||
## Using external environment | ||
|
||
You can also run frontend connected to external environment like https://demo.nussknacker.io . To do that just invoke: | ||
``` | ||
npm run start:backend-demo | ||
``` | ||
For more options take a look at `package.json` | ||
|
||
# Tests | ||
|
||
## Unit (jest) tests | ||
|
||
```npm test``` | ||
``` | ||
npm test | ||
``` | ||
|
||
### Run tests from IntelliJ | ||
|
||
`Jest` should work out of the box, just click green arrow. | ||
`Jest` should work out of the box, just click play button. | ||
|
||
## E2E (cypress) tests | ||
_You should copy and fill `cypress.env.json.template` into `cypress.env.json` before start._ | ||
|
||
##### Image snapshots are **OS** and even resolution dependent! | ||
Background: Cypress is a framework for end-to-end frontend tests. It verifies correctness of results using captured image snapshots. | ||
It runs tests in browser connected to our frontend application at http://localhost:3000. It uses some variables available | ||
in `cypress.env.json` like credentials. | ||
|
||
> WARNING: Image snapshots are **OS** and even **resolution** dependent! Please add image snapshots captured on unified environment. | ||
### Run cypress tests | ||
|
||
There are a few ways to run cypress tests. | ||
|
||
#### Using cypress devServer | ||
|
||
Before this option you should run backend and frontend - take a look at "Run" chapter. | ||
|
||
After execution of: | ||
``` | ||
npm run test:e2e:dev | ||
``` | ||
you will see cypress devServer. It is useful to see what is done in each test, but it has some drawbacks: | ||
- "Run all specs" option doesn't work correctly | ||
- Produced image snapshots are OS dependent, so you shouldn't use it for purpose of changing captured image snapshots! | ||
|
||
#### Using devServer in CLI | ||
|
||
This option is similar to option above, but run all tests in CLI and the same - you shouldn't use it for purpose of changing captured image snapshots! | ||
``` | ||
npm run test:e2e | ||
``` | ||
|
||
#### Using Intellij Idea | ||
|
||
Thanks to [Cypress Plugin](https://plugins.jetbrains.com/plugin/13819-cypress-support) you can run tests by just clicking play button. | ||
|
||
Just like in options above, you should run backend and frontend before and the same - you shouldn't use it for purpose of changing captured image snapshots! | ||
|
||
#### Using unified linux environment | ||
|
||
This is the correct option if you want to add/modify image snapshots and make sure that it was done in deterministic way. | ||
It runs backend in docker container, frontend connected to this backend and after that it runs cypress tests also in docker container. | ||
``` | ||
npm run test:e2e:docker | ||
``` | ||
|
||
Compare, update (when needed) and commit **image snapshots** made with `BACKEND_DOMAIN` set to url of backend started with `npm run start-backend:docker` | ||
#### Using unified linux environment on already started backend | ||
|
||
#### Start server and test (CI) with already running BE | ||
This option is similar to above, but it speeds up test loop. You should run once: | ||
``` | ||
npm run start:backend-docker | ||
``` | ||
|
||
and after that you can run multiple times: | ||
``` | ||
npm run test:e2e:linux | ||
``` | ||
|
||
#### Using unified linux environment with update image snapshots mode enabled | ||
|
||
To run cypress test in mode that would update image snapshots, use the same commands as in two options above but with `:update` suffix: | ||
``` | ||
npm run test:e2e:docker:update | ||
``` | ||
or: | ||
``` | ||
npm run test:e2e:linux:update | ||
``` | ||
|
||
```npm test:e2e:ci``` | ||
### Fixing cypress tests | ||
|
||
#### Start BE, start FE server and test inside linux image (snapshots for **CI**) | ||
After some changes in frontend it might be needed to rewrite captured image snapshots. The easiest way is to: | ||
1. Run cypress tests using "Run cypress tests using unified linux environment with update image snapshots mode enabled" method | ||
2. Review changes in files e.g. using Intellij Idea changes diff | ||
3. Commit changes or do fixes in scenarios. | ||
|
||
```npm test:e2e:docker``` | ||
# Internationalization | ||
|
||
#### CLI test with running devServer | ||
```npm test:e2e``` | ||
We use `react-i18next` package for internalizations. This mechanism has priority of determinining value for given key (`i18next.t(key, default)`): | ||
1. label from `translations/$lng/main.json` which is served at `/assets/locales/$lng/main.json` resource | ||
2. `default` passed as an argument | ||
|
||
#### GUI test with running devServer | ||
```npm test:e2e:dev``` | ||
File `translations/$lng/main.json` is generated in `prebuild` phase based on defaults. During development (`start` scripts) is removed to avoid confusions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters