graphql-engine/console/cypress/README.md
Ikechukwu Eze d7bc20f023 console: improve cypress testing docs
GitOrigin-RevId: 5aa929010fdae8234a93b461d7408ef5889195a0
2021-03-19 08:29:56 +00:00

61 lines
2.5 KiB
Markdown

# Test
## Running all tests to generate coverage
1. Set the `TEST_MODE` field in `cypress.json` to `cli`
2. Run the command `npm run test` from the `console` directory to run all the tests.
You can also run the complete tests from the cypress electron app:
1. Set the `TEST_MODE` field in `cypress.json` to `cli`
2. Run `npm run cypress` from the `console` directory.
3. Click on `test_complete.js`
## Running tests individually
Tests are modularized into following modules:
- API-Explorer
- Data
- Migration Mode
- Create Table
- Insert Browse
- Modify Table
- Table Relationships
- Table and View Permissions
- Views
To run the tests for the modules individually (say for create table),
- Go to the `cypress.json` and set the `env > TEST_MODE` variable to `ui`.
```json
{
"env": {
"TEST_MODE": "ui"
}
}
```
- Run the command `npm run cypress` and click on `create-table > test.js`
## Writing Tests
- Read ups
- If this is your first time with cypress, check out this getting started [guide](https://docs.cypress.io/guides/getting-started/writing-your-first-test.html)
- Read cypress [best practices](https://docs.cypress.io/guides/references/best-practices.html)
- File Structure
The top-level directories in [console/cypress](../../console/cypress) are auto-generated by cypress except [helpers](../../console/cypress/helpers). To understand the use of each directory check out [Folder Structure](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Folder-Structure)
[helpers](../../console/cypress/helpers) directory is used for sharing reusable functions/constants across tests. Before adding a resubale function in this directory, consider if it will be better as a custom cypress command, if so, then add it to [Support](../../console/cypress/support) directory following this [guide](https://docs.cypress.io/api/cypress-api/custom-commands.html), preferrably to [command.ts](../../console/cypress/support/commands.ts) file.
- Adding a Test
Tests go to [integration](../../console/cypress/integration) directory, where there are folders corresponding to Components in [Services](../../console/src/components/Services) directory (The top-level routes on the console).
Each of these folders contains different test folders, named after the particular feature they are testing. For example [create-table](../../console/cypress/integration/data/create-table) folder tests the functionality of creating a table from the console UI.