You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 27, 2023. It is now read-only.
Currently Cypress tests are passing locally, but some of the test are failing in GitLab CI.
61
+
This project uses Pytest, Jest and Cypress for testing. This section describes the different ways to run tests locally.
62
62
63
-
To run Cypress locally you can either run Cypress directly on your computer against the containerized application (for active development), or you can run Cypress in a container against the containerized application (this should be the same environment in GitLab CI using docker-compose with dind).
63
+
To run Pytest and Jest, you can use `docker-compose exec`, or you can shell into the container.
64
64
65
-
To setup Cypress locally, run:
65
+
Using `docker-compose exec`:
66
66
67
67
```
68
-
npm install cypress --save
68
+
docker-compose exec backend pytest
69
+
```
70
+
71
+
```
72
+
docker exec -it backend bash
73
+
root@b24c4206002e:/code# pytest
74
+
```
75
+
76
+
To run Jest tests, you can run:
77
+
78
+
```
79
+
docker-compose exec frontend npm run test
80
+
```
81
+
82
+
## Integration tests
83
+
84
+
Cypress can be used in an interactive mode with a UI, or it can be used in a headless way (such as in GitLab CI).
85
+
86
+
## Running Cypress Interactively
87
+
88
+
To run Cypress tests interactively, install Cypress in the root of the project:
89
+
90
+
```
91
+
npm install cypress
69
92
```
70
93
71
94
Then open Cypress with:
72
95
73
96
```
74
-
$(npm bin)/cypress open
97
+
$(npm bin)/cypress open --config baseUrl=http://localhost
98
+
```
99
+
100
+
Click on the button "Run all specs", and the tests will start running in a new browser window with a log of Cypress actions and test statements displayed on the left side.
101
+
102
+
## Run Cypress in headless mode
103
+
104
+
There are two ways to run Cypress in headless mode. You can run Cypress against the `docker-compose` file in `compose/test.yml`, or you can run the Cypress test using `gitlab-runner`.
105
+
106
+
### Using `compose/test.yml`
107
+
108
+
To run the test locally against the production image, run the following:
109
+
110
+
```
111
+
docker-compose -f compose/test.yml up --build
112
+
```
113
+
114
+
This will build a special environment that resembles the environment used in GitLab CI. It brings up three containers: redis, postgres and backend. The backend serves several purposes: it runs the Django webserver, it runs the ASGI server used by Django Channels, and it runs celery tasks synchronously, and it also serves the Vue application through Django templates and static files. See the Dockerfile located at `backend/scripts/prod/Dockerfile` for details on how this works.
115
+
116
+
Make sure that Cypress is properly installed with:
117
+
118
+
```
119
+
$(npm bin)/cypress verify
120
+
```
121
+
122
+
Then start the tests with:
123
+
124
+
```
125
+
$(npm bin)/cypress run --config baseUrl=http://localhost:9000
126
+
```
127
+
128
+
You could also run these tests in the interactive mode using `compose/test.yml` with the following command:
129
+
130
+
```
131
+
$(npm bin)/cypress open --config baseUrl=http://localhost:9000
132
+
```
133
+
134
+
Note that this is similar to the previous command, but we are using the `open` command instead of the `run` command.
135
+
136
+
### Using `gitlab-runner`
137
+
138
+
It can be useful to debug your `.gitlab-ci.yml` jobs before pushing changes to GitLab. This gives us a faster feedback loop, and it doesn't use any of the CI minutes on your free (2000 minutes/month) or paid GitLab plans.
139
+
140
+
There is a little bit of setup needed to run Cypress tests with `gitlab-runner`.
141
+
142
+
First, you need to install `gitlab-runner` on your machine.
143
+
144
+
Next, you need to start a local registry on you r computer. Run the following command ([taken from docker documentation](https://docs.docker.com/registry/deploying/)):
145
+
146
+
```
147
+
docker run -d -p 5000:5000 --restart=always --name registry registry:2
75
148
```
76
149
77
-
Run cypress tests locally by running the following commands. First build the application stack and cypress container:
150
+
Next, you need to build the production image that you will use in the test. To do this, run the following command:
docker tag compose_backend:latest localhost:5000/backend:latest
87
160
```
88
161
89
-
Then run cypress tests:
162
+
Then push the tagged image to the local registry:
90
163
91
164
```
92
-
docker-compose -f docker-compose.ci.yml -f cypress.yml up
165
+
docker push localhost:5000/backend:latest
93
166
```
94
167
168
+
Now that we have pushed the production image to our local registry, we can run the `e2e-local` job with `gitlab-runner`.
169
+
170
+
To do this, we need to make sure that the `e2e-local` job defined in `.gitlab-ci.yml` is not commented. To do this, remove the `.` in front of the job name (change `.e2e-local` to `e2e-local`).
171
+
172
+
Then, commit your changes in git. Gitlab runner requires that you commit changes before running tests. Run the GitLab CI job with the following command:
173
+
174
+
```
175
+
gitlab-runner exec docker e2e-local
176
+
```
177
+
178
+
Before you push your changes to GitLab, make sure that you uncomment the `e2e-local` job by adding `.` in front of it (`.e2e-local`).
0 commit comments