Test Runner
Condo uses Jest with the Jasmine2 test runner. Tests live alongside the code they test, inside each domain folder.Test Projects
The Jest configuration (apps/condo/jest.config.js) defines three separate test projects:
| Project | File Pattern | Purpose |
|---|---|---|
schema tests | domains/**/schema/*.test.js | Keystone schema integration tests |
schema specs | domains/**/schema/**/*.spec.[tj]s | Unit tests for schema utilities |
main | All other .spec.[tj]s files | General unit and integration tests |
File Naming Conventions
*.test.js— Schema integration tests. Use Keystone test utilities and run against a real database.*.spec.js/*.spec.ts— Unit tests. Mock dependencies and test logic in isolation.
Running Tests
Test Modes
The@open-condo/keystone/test.utils package supports two modes:
Real Client Mode
Sends actual HTTP/1.1 requests to a running server. Best for end-to-end and production validation testing. This is the default mode.
Fake Client Mode
Uses
supertest to simulate requests within a single process. Best for debugging — lets you set IDE breakpoints anywhere in the request/response cycle.Common Testing Patterns
Mock Keystone Context
When testing code that receives a Keystone context, mock it with a sudo sub-context:Mock Class Instances
When a class is mocked, use a plain mock object and check against it directly. Do not usetoBeInstanceOf with mocked classes:
Faker Usage
Use the correctfaker API for UUID generation:
Testing Philosophy
Test the public API, not internals
Do not export constants or helper functions solely for testing purposes. Test behavior through the public interface instead:Simplicity over coverage
- Simple tests that cover the common path are more maintainable than exhaustive tests covering every edge case.
- When mocking becomes very complex, it is usually a signal to simplify the code or switch to an integration test.
- Prefer integration tests over exposing internals.
Mock isolation
Each test should set up its own mocks and tear them down after. Do not share mutable mock state between tests.Linting
Static Analysis (SAST)
Condo uses Semgrep for static application security testing. It runs automatically on CI.Suppressing False Positives
If Semgrep flags code that is intentionally safe, suppress it with a// nosemgrep: comment. Always include an explanation of why the code is safe: