This document describes the testing setup and procedures for PgForge.
PgForge uses Bun's built-in testing framework which provides:
- Fast test execution
- TypeScript support out of the box
- Code coverage reporting
- Watch mode for development
# Run all tests
bun test
# Run tests in watch mode (re-runs on file changes)
bun test --watch
# Run tests with coverage report
bun test --coverage
# Run type checking
bun run typecheck- During development: Use
bun test --watchto automatically run tests as you code - Before committing: Run
bun testandbun run typecheckto ensure all tests pass - For coverage: Use
bun test --coverageto see test coverage metrics
Tests are located alongside the source files with the .test.ts extension:
src/
├── config/
│ ├── types.ts
│ └── types.test.ts
├── utils/
│ ├── validation.ts
│ ├── validation.test.ts
│ ├── system.ts
│ └── system.test.ts
└── instance/
├── manager.ts
└── manager.test.ts (to be added)
-
Validation Functions (
src/utils/validation.test.ts)- Instance name validation
- Port number validation
- Network address validation
- Database/user name validation
- Encoding validation
- Memory size validation
- Complete configuration validation
- Port availability checking
-
System Requirements (
src/utils/system.test.ts)- System requirement definitions
- Command validation
- Version requirement checking
-
Configuration Types (
src/config/types.test.ts)- TypeScript interface validation
- Enum constraint testing
- Configuration structure validation
- Instance manager operations
- Configuration file parsing
- CLI command integration
- Error handling scenarios
- System integration tests
The project includes a GitHub Actions workflow that runs:
- Test Suite: All unit and integration tests
- Type Checking: TypeScript compilation validation
- Build Verification: Ensures the application builds successfully
- Binary Creation: Tests binary compilation
To set up CI/CD, copy the workflow file:
cp .github-workflows-ci.yml .github/workflows/ci.ymlCreate .test.ts files alongside your source files:
import { describe, test, expect } from 'bun:test';
import { yourFunction } from './your-module.js';
describe('Your Module', () => {
test('should do something', () => {
expect(yourFunction('input')).toBe('expected');
});
});For testing CLI commands and system interactions:
import { describe, test, expect } from 'bun:test';
import { spawn } from 'child_process';
describe('CLI Integration', () => {
test('should show help', async () => {
// Test CLI command execution
});
});- Test Structure: Use descriptive
describeblocks andtestnames - Assertions: Use specific assertions (
toBe,toEqual,toContain, etc.) - Edge Cases: Test both success and failure scenarios
- Isolation: Each test should be independent and not rely on other tests
- Mock External Dependencies: Use mocks for file system, network calls, etc.
The test configuration is minimal since Bun handles most setup automatically:
- Test Files:
**/*.test.ts - Module Resolution: Uses the same TypeScript configuration as the main project
- Import/Export: ES modules with
.jsextensions in imports (for compatibility)
Bun's test runner is extremely fast:
- Typically runs all tests in under 100ms
- Supports parallel test execution
- Hot reloading in watch mode
To debug failing tests:
- Verbose Output: Add
console.logstatements - Isolated Testing: Run specific test files
- Watch Mode: Use
--watchto quickly iterate - Type Checking: Run
bun run typecheckfor TypeScript errors