This document provides instructions on how to run unit tests (using Jest) and end-to-end tests (using Cypress) in the revolutionary_farmers/web
project. It also includes prerequisites and tips to ensure the tests run successfully.
Before running any tests, make sure the following prerequisites are met:
- Install Node.js version 18 (recommended).
- Install PNPM globally:
npm install -g pnpm
Navigate to the web directory and install dependencies:
cd web
pnpm install
Ensure all necessary environment variables are properly set up. If a .env
file is required, it should exist in the web directory.
Ensure the development server can start without errors:
pnpm start
pnpm test
- Run tests in watch mode:
pnpm test:watch
- Generate a coverage report:
pnpm test:coverage
Jest is preconfigured in the project. Ensure the following:
- The
jest.config.js
file exists in the web directory. - Dependencies like
jest
,@testing-library/react
, and@testing-library/jest-dom
are installed.
- Run Cypress in the terminal (headless mode):
pnpm test:e2e
- Open Cypress GUI:
pnpm test:e2e:open
- Run Cypress tests in CI mode:
pnpm test:e2e:ci
Cypress is preconfigured in the project. Ensure the following:
- The
cypress.config.js
file exists in the web directory. - Cypress dependencies like
cypress
andstart-server-and-test
are installed. - Tests are located in the
cypress/e2e
directory.
Cypress tests require the development server to be running. The test:e2e:ci
script handles this automatically using start-server-and-test
. If running tests manually, ensure the server is started:
pnpm start
If tests fail due to dependency issues, try clearing and reinstalling dependencies:
pnpm install --frozen-lockfile
Ensure the code passes linting and formatting checks before running tests:
pnpm lint
pnpm prettier --check "src/**/*.{js,jsx,ts,tsx,json,css,md}"
Ensure the development server port (http://localhost:3000) is not occupied by another process.
For Cypress tests, ensure the backend and database (if applicable) are correctly set up and populated with test data.
- For Jest: Add
--verbose
to thepnpm test
command for detailed logs. - For Cypress: Use the GUI (
pnpm test:e2e:open
) to debug test flows visually.