-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: reintroduce end-to-end UI tests with cypress
A recent commit [1] removed the stale, unused end-to-end tests. In their place, add newly-written tests that can run headlessly in TeamCity (via Docker) as a quick-failing health check and as a more exhaustive suite. [1] 3d171b2 (ui: remove unused end-to-end UI tests, 2022-07-25) Release note: None
- Loading branch information
Showing
27 changed files
with
3,140 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
build="$(dirname $(dirname $(dirname $(dirname $(dirname "${0}")))))" | ||
# for tc_prepare, tc_start_block, and friends | ||
source "$build/teamcity-support.sh" | ||
# for build_docker_image and run_tests | ||
source "$build/teamcity/cockroach/ci/tests/ui_e2e_test_impl.sh" | ||
|
||
tc_prepare | ||
|
||
tc_start_block "Load cockroachdb/cockroach-ci image" | ||
load_cockroach_docker_image | ||
tc_end_block "Load cockroachdb/cockroach-ci image" | ||
|
||
tc_start_block "Run Cypress health checks" | ||
cd $root/pkg/ui/workspaces/e2e-tests | ||
run_tests health | ||
tc_end_block "Run Cypress health checks" |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
build="$(dirname $(dirname $(dirname $(dirname $(dirname "${0}")))))" | ||
# for tc_prepare, tc_start_block, and friends | ||
source "$build/teamcity-support.sh" | ||
# for build_docker_image and run_tests | ||
source "$build/teamcity/cockroach/ci/tests/ui_e2e_test_impl.sh" | ||
|
||
tc_prepare | ||
|
||
tc_start_block "Load cockroachdb/cockroach-ci image" | ||
load_cockroach_docker_image | ||
tc_end_block "Load cockroachdb/cockroach-ci image" | ||
|
||
tc_start_block "Run Cypress health checks" | ||
cd $root/pkg/ui/workspaces/e2e-tests | ||
run_tests health | ||
tc_end_block "Run Cypress health checks" |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
function load_cockroach_docker_image() { | ||
docker load --input upstream_artifacts/cockroach-docker-image.tar.gz &> artifacts/docker-load.log || (cat artifacts/docker-load.log && false) | ||
rm artifacts/docker-load.log | ||
} | ||
|
||
function run_tests() { | ||
SPEC_ARG="" | ||
if [ "health" = "${1:-'EMPTY'}" ]; then | ||
SPEC_ARG="--spec 'cypress/e2e/health-check/**'" | ||
fi | ||
|
||
run docker compose run cypress -- $SPEC_ARG | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"root": true, | ||
"extends": "@cockroachlabs/eslint-config", | ||
"settings": { | ||
"react": { | ||
"pragma": "React", | ||
"version": "17.0" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
artifacts | ||
videos | ||
screenshots |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
load("@npm_e2e_tests//eslint:index.bzl", "eslint_test") | ||
|
||
eslint_test( | ||
name = "lint", | ||
data = [ | ||
".eslintrc.json", | ||
"cypress", | ||
"cypress.config.ts", | ||
"//pkg/ui/workspaces/eslint-plugin-crdb", | ||
"@npm_e2e_tests//@cockroachlabs/eslint-config", | ||
"@npm_e2e_tests//@typescript-eslint/eslint-plugin", | ||
"@npm_e2e_tests//@typescript-eslint/parser", | ||
"@npm_e2e_tests//eslint-plugin-prettier", | ||
"@npm_e2e_tests//eslint-plugin-react", | ||
"@npm_e2e_tests//eslint-plugin-react-hooks", | ||
"@npm_e2e_tests//prettier", | ||
], | ||
templated_args = [ | ||
"--ext .ts", | ||
"-c", | ||
"$$(rlocation $(rootpath .eslintrc.json))", | ||
"$$(rlocation $(rootpath cypress))", | ||
"$$(rlocation $(rootpath cypress.config.ts))", | ||
], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# End-to-end Tests for CockroachDB UI | ||
This package contains end-to-end tests for the CockroachDB web UI served (by | ||
default) on port 8080. Tests are run via [Cypress](https://cypress.io) and | ||
use a combination of the default Cypress API and the dom-testing-library queries | ||
provided by [Cypress Testing | ||
Library](https://testing-library.com/docs/cypress-testing-library/intro). | ||
|
||
## Running Tests Locally | ||
### Via `yarn` | ||
If you've already built a `cockroach` binary and installed the dependencies in | ||
this directory with `yarn`, these tests can be run with `yarn` directly: | ||
|
||
```sh | ||
yarn test # run all tests | ||
yarn test ./path/to/some/file.cy.ts # run only a single test file | ||
``` | ||
|
||
For "headed" test development, in which the Cypress UI and a browser are | ||
visible, run `yarn test:debug` and choose a test file in the Cypress UI. | ||
|
||
### Via `dev` | ||
The standard `dev` CLI used for other CockroachDB tasks can be used to run all | ||
(or a selected subset) of end-to-end tests via: | ||
|
||
```sh | ||
dev ui e2e # run all tests | ||
dev ui e2e ./path/to/some/file.cy.ts # run only a single test file | ||
``` | ||
|
||
This will ensure the relevant NPM dependencies are installed and build | ||
CockroachDB (if necessary) before running any tests, which is especially helpful | ||
during a bisect. For more information, see `dev ui e2e --help`. | ||
|
||
For "headed" test development, in which the Cypress UI and a browser are | ||
visible, run `dev ui e2e --headed` and choose a test file in the Cypress UI. | ||
|
||
## Running Tests in TeamCity | ||
For CI purposes, these tests are also run in TeamCity via Docker's [Compose | ||
V2](https://docs.docker.com/compose) by combining the [CockroachDB Docker | ||
image](https://github.com/cockroachdb/cockroach/tree/master/build/deploy) from a | ||
[previous build | ||
step](https://teamcity.cockroachdb.com/buildConfiguration/Cockroach_ScratchProjectPutTcExperimentsInHere_JaneDockerImage) | ||
with an [upstream Cypress docker | ||
image](https://hub.docker.com/r/cypress/browsers). Testing this configuration | ||
requires a bit of manual file movement and is out of scope for this document. | ||
|
||
## Cluster Management in Tests | ||
Regardless of how tests are launched, each test suite spins up a single-node | ||
cluster with an empty 'movr' database that listens only on localhost. The test | ||
scripts waits for the HTTP server to be listening on port 8080 before invoking | ||
`cypress`, and tears down the cluster when `cypress` exits. | ||
|
||
## Health Checks vs All Tests | ||
Each CockroachDB pull request results in only the tests in | ||
`./cypress/e2e/health-checks` being executed. These are intended to confirm only | ||
the most basic functionality of the UI, to ensure it hasn't been completely | ||
broken or accidentally removed. A more comprehensive suite including all tests | ||
is run in a separate TeamCity job. | ||
|
||
In general: put only simple, short-lived tests in the health-checks tree. |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -uemo pipefail | ||
|
||
set -x | ||
|
||
# Copy the /e2e tree into /scratch and remove any existing node_modules, to | ||
# prevent files with unexpected owners from escaping | ||
mkdir /scratch | ||
cp --recursive --no-target-directory --no-preserve=owner /e2e /scratch | ||
cd /scratch | ||
|
||
# Write a minimal .yarnrc mirroring the one in cockroach.git/pkg/ui, to avoid | ||
# mounting that entire tree. | ||
echo "yarn-offline-mirror /yarn-vendor" > .yarnrc | ||
|
||
# Remove and reinstall any node_modules that may have been copied, since they're | ||
# potentially specific to the host platform. | ||
rm -rf node_modules/ | ||
yarn install --force --offline | ||
|
||
# Run tests, passing extra CLI arguments through to Cypress | ||
yarn cy:run "$@" |
Oops, something went wrong.