This document outlines testing practices and policies for Paths-LE development.
No broken or failed tests are allowed in commits.
All tests must pass before code can be committed or merged. This ensures code quality and prevents regressions.
bun run testbun run test:coveragebun run test:performancebun run test:watchbun x vitest run src/utils/pathResolver.test.tsLocated in src/**/*.test.ts:
- Pure function tests - Test extraction logic in isolation
- Utility tests - Test helper functions, path resolution
- Configuration tests - Test config validation
Located in test-fixtures/:
- Monorepo tests - Test complex directory structures
- Symlink tests - Test symbolic link handling
- Cross-platform tests - Ensure Windows/Unix path compatibility
- Minimum Coverage: 80% across branches, functions, lines, statements
- Critical Paths: All extraction logic must be tested
- Error Handling: All error paths must be covered
- Edge Cases: Boundary conditions must be tested
- Security Tests: Path traversal, injection, symlink exploits
- All tests pass (
bun run test) - No broken tests
- No skipped tests (unless intentionally)
- Type checking passes (
bun x tsc -p ./) - Linting passes (
bun run lint) - Coverage meets minimum (80%)
The CI pipeline automatically:
- Runs all tests on Ubuntu, macOS, and Windows
- Generates coverage reports
- Verifies all tests pass
- Fails the build if any tests fail
- Don't commit the failure - Fix the test or the code
- Run locally first - Verify fix works before pushing
- Check all platforms - Ensure fix works on Linux/Windows (case sensitivity, paths, etc.)
- Update test if needed - If behavior changed intentionally, update test
- Case sensitivity - Use exact case for file references (
README.mdnotreadme.md) - Path separators - Use platform-agnostic path handling
- Mock issues - Ensure mocks are properly reset in
beforeEach - Timing issues - Avoid
async/awaitin tests when possible, use static imports
// ✅ Good
it('should extract relative paths from JavaScript imports', () => {
// ...
});
// ❌ Bad
it('works', () => {
// ...
});// ✅ Good - separate tests
it('should extract relative paths', () => { /* ... */ });
it('should exclude npm packages', () => { /* ... */ });
// ❌ Bad - multiple concerns
it('should extract paths and exclude npm', () => { /* ... */ });it('should resolve canonical paths', () => {
// Arrange
const basePath = '/project';
const relativePath = '../parent/file.js';
// Act
const resolved = resolvePath(basePath, relativePath);
// Assert
expect(resolved).toBe('/parent/file.js');
});beforeEach(() => {
vi.clearAllMocks();
// Reset mocks to default state
});Always use exact case for file references:
// ✅ Good - works on all platforms
const content = readSampleFile('README.md');
// ❌ Bad - fails on Linux
const content = readSampleFile('readme.md');Use platform-agnostic path handling:
import { join, sep } from 'path';
const filePath = join(SAMPLE_DIR, filename);
// Use sep for platform-specific separator testsTest both path formats:
// Test Windows paths
it('should handle Windows paths', () => {
const path = 'C:\\Users\\file.js';
expect(extractPaths(path)).toContain('C:\\Users\\file.js');
});
// Test Unix paths
it('should handle Unix paths', () => {
const path = '/home/user/file.js';
expect(extractPaths(path)).toContain('/home/user/file.js');
});Paths-LE includes 64 security tests covering:
- Path Traversal -
../and..\\attacks - Symlink Exploits - Symbolic link resolution
- Injection Attacks - Malicious path components
- Canonical Resolution - Security implications
Always test security-sensitive code paths.
Performance benchmarks are run separately:
bun run test:performancePerformance tests validate:
- Large file handling (1MB+)
- Throughput metrics
- Memory usage
- Execution time
See Performance Documentation for details.
Coverage reports are generated automatically:
- Location:
coverage/index.html - Format: HTML, LCOV, JSON
- CI/CD: Coverage uploaded as artifact
- Target: 80% minimum across all coverage types
Tests run automatically on:
- Ubuntu (latest)
- macOS (latest)
- Windows (latest)
All platforms must pass for the build to succeed.
Consider setting up pre-commit hooks to run tests before commits:
# Install husky (if needed)
bun add -d husky
# Add pre-commit hook
echo "bun run test" > .husky/pre-commitIf you encounter test failures:
- Run locally - Verify it fails consistently
- Check CI logs - See platform-specific errors
- Reproduce - Document steps to reproduce
- Fix or report - Either fix or create an issue
- Performance Monitoring - Performance testing and benchmarks
- Architecture - Testing approach and strategy
- Commands - Command testing guidelines