This directory contains comprehensive tests for all CodeKeeper validation scripts to ensure they work correctly and don't break when you make changes.
For rapid feedback during development:
# Run all tests
npm test
# Quick validation check
node tests/quick-test.js
# Test specific validation script
npm run test:as-casts
npm run test:barrel-files
npm run test:relative-imports
npm run test:jsdoc
npm run test:complexity
npm run test:structureEach validation script has corresponding test fixtures with known violations:
as-casts/- Files with good/bad TypeScriptascast patternsbarrel-files/- Legitimate vs problematic barrel/index filesrelative-imports/- Examples of deep relative imports vs proper alias usagejsdoc/- Files with missing vs proper JSDoc documentationcomplexity/- Simple vs overly complex filesdirectory-structure/- Different project organization patterns
Comprehensive test suite that:
- ✅ Verifies scripts correctly identify violations in bad files
- ✅ Confirms scripts pass good files without false positives
- ✅ Counts expected number of violations
- ✅ Tests all validation scripts automatically
- ✅ Provides detailed pass/fail reporting
When you add a new validation rule or modify existing ones:
- Create test fixtures in the appropriate
tests/fixtures/directory - Update test configuration in
test-runner.js:'your-script-name': { shouldFail: ['tests/fixtures/your-test/bad-file.ts'], shouldPass: ['tests/fixtures/your-test/good-file.ts'], expectedViolations: 2, // Number of violations expected }
- Run tests to verify everything works:
npm test
The test suite is designed to run in CI/CD pipelines to catch regressions:
# In your CI pipeline
npm test
# Exit code 0 = all tests pass
# Exit code 1 = some tests failedCurrent test coverage includes:
| Validation Script | Test Status | Fixtures |
|---|---|---|
| check-as-casts | ✅ | bad/good TypeScript casts |
| check-barrel-files | ✅ | barrel exports vs legitimate index files |
| check-relative-imports | ✅ | deep imports vs alias usage |
| check-jsdoc | ✅ | missing vs proper documentation |
| check-file-complexity | ✅ | complex vs simple files |
| check-directory-structure | ✅ | various project structures |
If tests fail:
-
Run individual tests to isolate the issue:
npm run test:as-casts
-
Check test output for specific violation details
-
Verify test fixtures still match expected patterns
-
Update configurations if validation rules changed
- Test both positive and negative cases - files that should pass AND fail
- Use realistic code examples in test fixtures
- Keep fixtures simple but representative of real-world code
- Update tests when changing validation rules
- Run tests before committing changes
This ensures CodeKeeper's validation scripts remain reliable and catch the issues they're designed to prevent! 🛡️