Skip to main content
Figentra follows a test pyramid strategy: a broad base of fast unit tests, a mid-layer of integration tests that verify service boundaries, and a thin layer of end-to-end tests that validate complete user flows. This balance keeps the suite fast during development while giving you confidence that the system works as a whole. Every package you ship must include tests; coverage thresholds are verified automatically on each build.

Test Types

Unit Tests

Test a single function or class in complete isolation. Mock all external dependencies. Use the .test.ts suffix. These run on every save and should complete in milliseconds.

Integration Tests

Test multiple modules together or verify a service boundary such as a database query or HTTP handler. Use the .spec.ts suffix. These may spin up real infrastructure using containers.

E2E Tests

Test full user flows from the outside — HTTP request to response, or browser interaction to assertion. Live in tests/e2e/. Run in CI against a staging environment.

Test Framework

All Figentra projects use Vitest as the test runner. Vitest provides native TypeScript support, a Jest-compatible API, and first-class support for ESM — no transpilation step required. Add a vitest.config.ts at the root of each package:
vitest.config.ts
Setting globals: true makes describe, it, and expect available without explicit imports — matching the Jest experience most contributors already know.

Writing a Unit Test

The example below tests a UserService class. Notice that the test file lives in tests/ and imports from ../src/:
user-service.test.ts
Follow the Arrange / Act / Assert pattern inside every it block. Keep each test focused on a single behaviour so failures are easy to diagnose.

Coverage Requirements

1

80%+ line coverage on all packages

Every published package must reach at least 80% line coverage. The build will fail if any package falls below this threshold, so check your coverage report before publishing.
2

100% coverage on critical paths

Error handling code, authentication logic, and data validation must have 100% line and branch coverage. Mark these files explicitly in your vitest.config.ts using the include option under coverage.
3

No untested exports

Every symbol exported from src/index.ts must have at least one direct test. Use the coverage report to identify untested exports before opening a pull request.

Running Tests

Shared Test Utilities

Use the @figentra/testing package for common setup and teardown helpers — database seed/reset utilities, mock factory functions, and custom Vitest matchers. Importing from @figentra/testing keeps boilerplate out of individual test files and ensures consistent behavior across the monorepo.
user-service.spec.ts