This guide explains how to run tests, write new tests, and understand the testing infrastructure for the Istex TEI Viewer project.
The project uses a two-tier testing approach:
- Unit Tests - Fast, isolated tests for components and functions
- End-to-End (E2E) Tests - Full integration tests simulating real user scenarios
File: vitest.config.ts
Configured to test all packages except E2E using real browser environment with Playwright.
Unit tests are co-located with source files using the .spec.tsx or .spec.ts extension.
Tests use vitest-browser-react for component rendering and Vitest Browser mode for user-centric tests. See test files for examples.
See makefile for available test commands.
Generate coverage reports with pnpm test --coverage.
File: packages/e2e/playwright.config.ts
Configured to automatically start the demo server and test against production or development builds.
E2E tests are in packages/e2e/src/ with test data in the testdata/ directory.
Tests use Playwright with standard patterns for user interaction, navigation testing, and visual regression. See test files in packages/e2e/src/ for examples.
See makefile for available E2E test commands (production and development modes).
Test documents are in packages/e2e/testdata/ covering various TEI structures and enrichment types.
Flaky tests:
- Add proper wait conditions:
await expect.element(element).toBeVisible() - Avoid fixed timeouts
- Check for race conditions
- Run test multiple times to verify stability
Slow tests:
- Mock expensive operations (API calls, file I/O)
- Use smaller test documents
- Parallelize independent tests
- Profile with
--reporter=verbose
Brittle tests:
- Use semantic queries (role, label) over CSS selectors
- Test behavior, not implementation
- Avoid testing internal state
- Keep tests focused on single behavior
For unit tests:
- Create minimal test fixtures inline or in test files
- Use builder pattern for complex objects
- Share common fixtures via test utilities
For E2E tests:
- Add TEI documents to testdata/
- Keep files minimal (only necessary elements)
- Name descriptively:
feature-scenario.tei - Document special cases in file comments
Follow standard testing practices: test behavior not implementation, use descriptive test names, keep tests isolated, and prefer user-centric assertions over implementation details.
Tests run automatically on pull requests and commits. See CI configuration for details.