Quick Reference
- Tests Location:
tests/directory- Unit Tests:
tests/unit/(Vitest)- E2E Tests:
tests/e2e/(Playwright) - 59 comprehensive tests- API Tests:
scripts/api-test.mjs- Direct endpoint testing- CI/CD:
.github/workflows/ci.yml
This document covers the testing infrastructure that enables safe JavaScript framework updates and catches regressions before they reach users.
| Layer | Tool | Speed | Coverage |
|---|---|---|---|
| Unit Tests | Vitest | < 1s | Utility functions, API clients |
| API Tests | Node.js | 5-10s | Direct endpoint validation |
| E2E Tests | Playwright | 30-60s | Critical user workflows (59 tests) |
- Vitest: Native ESM support, 2-3x faster than Jest, official Next.js 16 recommendation
- Playwright: GitHub-native integration, professional-grade browser automation
- happy-dom: Better ESM compatibility than jsdom for Next.js 16
# Unit tests (watch mode)
npm test
# Unit tests (single run)
npm run test:run
# Unit tests with coverage
npm run test:coverage
# E2E tests
npm run test:e2e
# E2E tests with browser UI
npm run test:e2e:ui
# API smoke tests
npm run test:poplar-smokeTests for individual functions and modules in isolation.
tests/unit/
├── api/
│ ├── auth.test.ts # loginPatric, loginRast, token handling
│ ├── biochem.test.ts # Solr compound/reaction queries
│ ├── modelseed.test.ts # Model, Media, Job API calls
│ └── workspace.test.ts # Workspace ls/get operations
└── utils/
└── exportCsv.test.ts # CSV generation utilities
Browser-based tests that verify complete user workflows.
tests/e2e/
├── auth.spec.ts # PATRIC/RAST login flow
├── browse-models.spec.ts # My Models page navigation
├── build-model.spec.ts # Plant model builder
├── media-workflow.spec.ts # Media editor
├── model-detail.spec.ts # Model detail tabs
└── run-fba.spec.ts # FBA analysis
import { describe, it, expect, vi, beforeEach } from 'vitest';
// Mock external dependencies
vi.mock('@/lib/api/external', () => ({
fetchData: vi.fn(),
}));
describe('Feature Name', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should do something specific', () => {
const result = someFunction(input);
expect(result).toBe(expected);
});
});describe('API Feature', () => {
let isApiAvailable = true;
beforeAll(async () => {
try {
await actualApiCall();
} catch (e) {
isApiAvailable = false;
}
});
it('should work when API available', async () => {
if (!isApiAvailable) return; // Graceful skip
const result = await actualApiCall();
expect(result).toBeDefined();
});
});import { test, expect } from '@playwright/test';
test.describe('Feature Flow', () => {
test.beforeEach(async ({ page }) => {
// Auth setup if needed
await page.goto('/');
});
test('should complete workflow', async ({ page }) => {
await page.click('[data-testid="action"]');
await expect(page.locator('.result')).toBeVisible();
});
});The test workflow (.github/workflows/test.yml) runs on:
| Event | Unit Tests | E2E Tests |
|---|---|---|
| Pull Request | Yes | No |
Push to develop |
Yes | Yes |
Push to master |
Yes | Yes |
| Secret | Description |
|---|---|
PATRIC_TOKEN |
PATRIC authentication token for E2E tests |
Coverage thresholds are set in vitest.config.ts:
thresholds: {
lines: 10, // Currently 10%, increase as tests grow
functions: 10,
branches: 10,
statements: 10,
}# Local development with tests
npm run test:run
# With coverage
npm run test:coverage
# E2E with browser UI
npm run test:e2e:uiNEXT_PUBLIC_USE_MODELSEED_API: 'true'
NEXT_PUBLIC_MODELSEED_API_URL: 'http://poplar.cels.anl.gov:8000'
PATRIC_TOKEN: ${{ secrets.PATRIC_TOKEN }}- Never commit tokens - Use environment variables only
- Skip on missing secrets - Tests should handle missing
PATRIC_TOKEN - No sensitive data - Use test accounts with limited access
- One assertion per test - Each test should verify one thing
- Descriptive names - Test names should describe expected behavior
- Arrange-Act-Assert - Structure tests clearly
- Fast feedback - Keep unit tests under 100ms
- Graceful degradation - Skip tests when APIs unavailable
- Real responses - Test against actual API responses when possible
- Error handling - Verify error paths work correctly
- Verify
PATRIC_TOKENis set in GitHub secrets - Check environment variables match local setup
- Review Playwright browser installation logs
- Increase timeout:
await expect(locator).toBeVisible({ timeout: 30000 }) - Check network connectivity in CI
- Verify dev server starts correctly
- Add more tests for untested code paths
- Increase threshold gradually as test suite grows
- Focus on critical paths first (API clients, auth)
- ARCHITECTURE.md - System architecture and API clients
- AUTHENTICATION.md - Auth system details
- WORKSPACE.md - Workspace API
tests/README.md- Quick reference for test commands