| name | testing |
| description | Testing — writing and running tests with bun:test, test patterns, validation. Trigger keywords: test, testing, unit test, integration test, bun test, spec, assertion. |
Testing — bun:test Patterns
How to write and run tests in the corvid-agent project.
Running Tests
fledge run test
bun test server/db/schema.test.ts
bun test --filter "agent"
Test File Convention
- Test files live next to the code they test:
foo.ts → foo.test.ts
- End-to-end tests live in
e2e/ (Playwright)
Writing Tests
import { describe, test, expect, beforeEach } from 'bun:test';
describe('MyModule', () => {
beforeEach(() => {
});
test('should do the expected thing', () => {
const result = myFunction(input);
expect(result).toBe(expected);
});
test('should handle edge case', () => {
expect(() => myFunction(null)).toThrow();
});
});
Assertions
expect(value).toBe(exact);
expect(value).toEqual(deep);
expect(value).toBeTruthy();
expect(value).toBeNull();
expect(value).toContain(item);
expect(value).toHaveLength(n);
expect(fn).toThrow();
expect(fn).toThrow('message');
Test Patterns
- No mocking the database — use real SQLite for integration tests
- Use descriptive test names that explain the expected behavior
- One assertion per concept — test one behavior at a time
- Arrange-Act-Assert pattern for test structure
- Clean up after tests — don't leave side effects
Validation Pipeline
Before committing, run the full verification lane:
fledge lanes run verify
Work tasks auto-run this pipeline and iterate up to 3 times on failure.
E2E Tests (Playwright)
cd e2e && npx playwright test
cd e2e && npx playwright test --ui
E2E tests live in e2e/ and test the full stack including the Angular frontend.