Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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

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)

@kathyavini kathyavini Apr 11, 2025

Copy link
Copy Markdown
Collaborator

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 dev db 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")


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

Copy link
Copy Markdown
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
Copy Markdown
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. 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.

Copy link
Copy Markdown
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
Copy Markdown
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
28 changes: 25 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ volumes:
minio-data:
export-node-modules:
postgres-data:
postgres-testdata:

@kathyavini kathyavini Apr 11, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 tmpfs.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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:

  1. Setting up an image that contains PostgreSql and the backend (to run the migrations) with all its dependencies and use it in the existing docker-compose.yaml
  2. Create a separate docker-compose.yaml with 2 services... 1 for the cypress-db and 1 for the backend so we create the DB first, execute the init script.sql and when it's done start the backend service that will run the migration.
  3. do the same as above using the existing docker compose under a testing profile (but it could look a bit more messy)

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:
Expand All @@ -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:

@kathyavini kathyavini Apr 11, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should it be called something like testing-db instead? I see you included the creation of test_farm which is not used by Cypress under the default config (it's just for the API tests). I thought maybe from the readme changes as well that this container could be used for both?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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: >-

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm getting an error about the options here that prevent me from running this file:

Screenshot 2025-04-10 at 5 14 47 PM

this syntax works for me though:

healthcheck:
  test: ["CMD", "pg_isready", "-U", "postgres"]
  interval: 5s
  timeout: 5s
  retries: 5

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
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
Copy Markdown
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