Testing
Zequel uses Vitest as its test runner with globals enabled. Test files live in src/tests/ and mirror the source tree structure.
Test Types
Unit Tests
Located in src/tests/unit/, subdivided into renderer/ and main/ to match the source layout. Unit tests are fast and isolated -- they do not require running databases or the full Electron environment.
Integration Tests
Located in src/tests/integration/. These tests connect to real database instances started via Docker Compose. Make sure the development databases are running before executing them:
bash
docker compose up -dEnd-to-End Tests
Located in src/tests/e2e/. These tests launch the full Electron application and interact with it programmatically.
Commands
bash
# Run all tests in watch mode
npm test
# Run unit tests only
npm run test:unit
# Run integration tests only (requires Docker databases)
npm run test:integration
# Run all tests with coverage report
npm run test:coverageWriting Tests
Test files follow this structure:
typescript
import { describe, it, expect, vi } from 'vitest';
describe('ConnectionService', () => {
it('should connect to database', () => {
const result = connectToDatabase();
expect(result).toBe('expected');
});
});Conventions
- Place test files in the
src/tests/directory mirroring the path of the source file being tested. For example, tests forsrc/main/db/postgres.tsgo insrc/tests/unit/main/db/postgres.test.ts. - Use
describeblocks to group related tests. - Use
vi.fn()andvi.mock()for mocking. - Write tests for both backend (main process) and frontend (renderer) code.
- Keep unit tests free of side effects. Mock external dependencies such as database clients and IPC channels.
- Integration tests should clean up after themselves (drop temporary tables, close connections).
