Testing During Development
How to locally test the app during development.
Local Unit Tests
Before submitting your updates, verify they pass all unit tests. Follow these steps to run tests locally:
-
Copy the example test environment file used by the API tests:
cp api/test/.env.test.example api/test/.env.test -
npm run test:client -
npm run test:api -
npm run test:packages:api -
npm run test:packages:data-provider -
npm run test:packages:data-schemas -
npm run test:packages:chat -
npm run test:allruns all of the suites above in sequence.
Static Checks
Commits also run the Static Checks CI job locally through the husky pre-commit hook (set HUSKY=0 to opt out). Run it by hand with npm run static-checks, or against a base branch with npm run static-checks -- --against origin/dev. npm run static-checks:full adds the slower gates (TypeScript, config migration tests, unused i18n keys, unused npm packages).
Running Tests Per-Workspace
Tests are run using Jest from their respective workspace directories. Target specific test files with patterns:
cd api && npx jest <pattern>
cd packages/api && npx jest <pattern>
cd packages/data-provider && npx jest <pattern>
cd packages/data-schemas && npx jest <pattern>
cd packages/chat && npx jest <pattern>
cd client && npx jest <pattern>Testing Philosophy
- Prefer real logic over mocks. Mock only what cannot be controlled locally, such as external HTTP APIs, rate-limited services, and non-deterministic system calls.
- Use spies when you need to assert that real functions were called with expected arguments.
- Use
mongodb-memory-serverfor MongoDB-backed tests so queries and schema validation run against real database behavior. - Cover loading, success, and error states for UI/data flows.
Tip
Use test/layout-test-utils for rendering components in frontend tests.
How is this guide?