Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

### Setup

1. Start the dedicated test database container with `docker compose --profile testing up testing-db`
1. Run the `dev` migrations `npm run migrate:dev:db` from `packages/api`.
1. Go to `packages/end-to-end` directory.
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 packages/api not in packages/end-to-end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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. 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My shell didn't prompt me! Did it prompt you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does ! maybe you need to scroll a bit.
I checked the CI and it has the same
This screenshot is from my shell:
image


## 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

Expand Down
26 changes: 24 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ services:
volumes:
- ./initdb.d:/docker-entrypoint-initdb.d
- postgres-data:/var/lib/postgresql/data

testing-db:
container_name: litefarm-test-db
image: postgres:13
ports:
- "5434: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
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 5s
timeout: 5s
retries: 5
profiles:
- testing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put this on a profile (e.g. testing) so it doesn't start up with docker compose up? We want to keep docker compose up as the default, no-config way to get started and it will now error on the port if both databases are included

Bind for 0.0.0.0:5433 failed: port is already allocated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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
Expand Down
Loading