-
Notifications
You must be signed in to change notification settings - Fork 103
Improve Cypress test infrastructure #3736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: integration
Are you sure you want to change the base?
Changes from 2 commits
e976a9a
712e6c6
f3cc680
e758479
7440611
fdd6a41
96975b8
10e7d9a
f4a8712
d68f98d
cc38cae
523a54e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,27 +206,52 @@ If you are unable to use Docker, please contact a core team member to get instru | |
|
|
||
| # Testing | ||
|
|
||
| ## api | ||
| ## WebApp E2e tests | ||
|
|
||
| To be able to run the existing Cypress E2e tests, you'll need to have a DB configured with the information from the `dev` environment (this is how it is setup our pipeline) | ||
|
|
||
| ### Setup | ||
|
|
||
| 1. (Only if not already configured) Using a container with the DB hosted in there is recommended and to be able to spin up such container `docker compose up cypress-db`. | ||
| 1. Go to `packages/end-to-end` directory. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why your numbers are all "1" 😂 Also the migration scripts all live in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the "1's" is one of the best tricks Markdown has 😂 this way you avoid editing the numbers whenever there's a change in the order and they will render in the browser properly, for instance . |
||
| 1. Run the `dev` migrations `npm run migrate:dev:db`. | ||
| 1. Install the E2e test dependencies`npm i`. | ||
|
|
||
| ### Execution | ||
|
|
||
| 1. Run the tests `npx cypress run`. | ||
|
|
||
| As result videos and logs are going to be stored in the directories prompted by the shell. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My shell didn't prompt me! Did it prompt you?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it does ! maybe you need to scroll a bit. |
||
|
|
||
| ## API Integration tests | ||
|
|
||
| To run [ESLint](https://eslint.org/) checks execute `npm run lint` | ||
|
|
||
| The [chai.js](https://www.chaijs.com/) and [jest](https://jestjs.io/) libraries automate tests that run real database operations using a dedicated database named `test_farm`, distinct from the `pg-litefarm` database that the app normally uses. | ||
|
|
||
| You'll want to confirm that you have an empty `test_farm` database (otherwise use your preferred database client to create one) before continuing with the following: | ||
|
|
||
| ### Setup | ||
|
|
||
| 1. In a terminal, navigate to the `packages/api` folder. | ||
| 2. Execute `npm run migrate:testing:db` to set up the test database. | ||
| 3. Execute `npm test` to launch the tests. Or, to generate test coverage information, run `npm test -- --coverage .` and then see the `coverage/index.html` file. | ||
| 1. Execute `npm run migrate:testing:db` to set up the test database. | ||
|
|
||
| ### Execution | ||
|
|
||
| 1. Execute `npm test` to launch the tests. | ||
| 1. (Optionally) to generate test coverage information, run `npm test -- --coverage .` and then see the `coverage/index.html` file. | ||
|
|
||
| While the tests do attempt to clean up after themselves, it's a good idea to periodically use `psql` or your database client to `DROP` and `CREATE` the `test_farm` database, followed by the migrations from step 2 above. | ||
|
|
||
| ## webapp | ||
| ## WebApp testing | ||
|
|
||
| To run [ESLint](https://eslint.org/) checks execute `pnpm lint` | ||
|
|
||
| Since this is a mobile web application, webapp should be viewed in a mobile view in the browser. | ||
|
|
||
| You can also test LiteFarm on your actual mobile device using the network adddress returned by `vite --host` when you start the webapp in development mode. To do this, also update `VITE_API_URL` in your `webapp/.env` file from localhost to that address (or your computer's network name) and the appropriate API port. Most of LiteFarm can be tested like this, but please note that Google SSO and some other functionality will not work over the local network. | ||
| You can also test LiteFarm on your actual mobile device using the network adddress returned by `vite --host` when you start the webapp in development mode. | ||
| To do this, also update `VITE_API_URL` in your `webapp/.env` file from localhost to that address (or your computer's network name) and the appropriate API port. | ||
| Most of LiteFarm can be tested like this, but please note that Google SSO and some other functionality will not work over the local network. | ||
|
|
||
| # ngrok | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ volumes: | |
| minio-data: | ||
| export-node-modules: | ||
| postgres-data: | ||
| postgres-testdata: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious -- why the persistent volume? To avoid running the migration again? Could the migration be added to the setup for the test db container instead, and the data purged when bringing down the container? I think a testing db is the perfect case for for wanting start fresh each time the container runs, e.g. with Unfortunately I think at least some of the end-to-end tests don't work well being run repeatedly -- I think there are some issues with spotlights, which have to be clicked through on first login but aren't shown subsequently. When I had to work on end-to-end locally I actually needed a script that dropped and re-migrated between each run.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are totally right, we don't need a volume here as the whole idea is to spin up a fresh DB with whatever is necessary to run the tests, my bad :) I need to check about running the migration at the setup to me it sounds that we have 3 options:
If I'm over complicating let me know so we can figure out a simpler solution. About the E2e issues, I will try to pay close attention to them, if anything comes up I let you know hopefully with a fix. |
||
|
|
||
| services: | ||
| db: | ||
|
|
@@ -15,8 +16,29 @@ services: | |
| environment: | ||
| POSTGRES_PASSWORD: "postgres" | ||
| volumes: | ||
| - ./initdb.d:/docker-entrypoint-initdb.d | ||
| - ./initdb.d:/docker-entrypoint-initdb.d:Z | ||
| - postgres-data:/var/lib/postgresql/data | ||
|
|
||
| cypress-db: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be called something like
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| container_name: litefarm-test-db | ||
| image: postgres:13 | ||
| ports: | ||
| - "5433:5432" | ||
| environment: | ||
| POSTGRES_DB: "test_farm" | ||
| POSTGRES_USER: "postgres" | ||
| POSTGRES_PASSWORD: "postgres" | ||
| POSTGRES_HOST: postgres | ||
| POSTGRES_PORT: 5432 | ||
| volumes: | ||
| - ./initdb.d:/docker-entrypoint-initdb.d:Z | ||
| - postgres-testdata:/var/lib/postgresql/data | ||
| options: >- | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's strange, I used your suggestion and both worked for me, although Im leaving yours so it's compatible with anyone else :) |
||
| --health-cmd pg_isready | ||
| --health-interval 5s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put this on a profile (e.g.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed ! |
||
| minio: | ||
| image: minio/minio:RELEASE.2023-06-09T07-32-12Z | ||
| restart: unless-stopped | ||
|
|
@@ -60,8 +82,8 @@ services: | |
| image: litefarm/node-awscli:latest | ||
| restart: unless-stopped | ||
| volumes: | ||
| - ./packages/api:/packages/api | ||
| - ./packages/webapp/public/locales:/packages/webapp/public/locales | ||
| - ./packages/api:/packages/api:Z | ||
| - ./packages/webapp/public/locales:/packages/webapp/public/locales:Z | ||
| - export-node-modules:/packages/api/node_modules | ||
| working_dir: /packages/api | ||
| entrypoint: ./dev.export.sh | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably push spinning up a container a little more strongly, because for sure you can run Cypress as long as you have a
devdb set up, but that's gonna pollute the DB with Cypress testing data and that's really no good! Maybe instead of 'you'll need to have a DB configured' maybe just go right to:"When running Cypress E2E tests, it's recommended to use a dedicated test database. This helps keep your main development database free from testing data."
(And similarly maybe remove 'Only if not already configured' because again having set up the main dev DB might feel like enough. I would just go right to
"Start the dedicated test database container with
docker compose up cypress-db")