Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

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 your .env.example file in the /api folder and rename it to .env

    cp .env.example ./api/.env
  • Add NODE_ENV=CI to your /api/.env file

  • 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

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 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-server for 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?