This guide covers testing practices for the Docker Compose Builder project, including snapshot testing workflow and troubleshooting.
The project uses a comprehensive test suite split across three categories:
Location: src/lib/docker-compose/__tests__/unit/
- Validation tests (33 tests)
- Generator tests (29 tests)
- Test individual functions and logic in isolation
Location: src/lib/docker-compose/__tests__/bdd/
- Edge case scenarios (18 tests)
- Quick start scenarios (9 tests)
- Full custom scenarios (13 tests)
- Test end-to-end workflows and user behaviors
Location: src/lib/docker-compose/__tests__/__verify__/
- API provider snapshots (9 tests)
- Quick start snapshots (8 tests)
- Full custom snapshots (6 tests)
- Validate generated YAML output against committed snapshots
Use Node.js ^20.19.0 || >=22.12.0 before running the commands below. This matches the Vite 8 runtime floor used by local development and CI.
npm test# Unit tests only
npm test -- src/lib/docker-compose/__tests__/unit/
# BDD tests only
npm test -- src/lib/docker-compose/__tests__/bdd/
# Snapshot verification tests only
npm run test:verifynpm run test:uinpm run test:coverageSnapshot testing ensures that generated Docker Compose YAML files maintain their expected structure over time. The project uses verifyjs for snapshot management with automatic scrubbing of dynamic content like timestamps.
src/lib/docker-compose/__tests__/__verify__/__snapshots__/
├── api-provider-snapshots.test.ts.snap
├── full-custom-snapshots.test.ts.snap
└── quick-start-snapshots.test.ts.snap
Update snapshots ONLY when:
- You intentionally change the YAML structure or format
- You add new configuration options that affect output
- You fix a bug that changed the generated YAML
- You are implementing a new feature that modifies output
DO NOT update snapshots when:
- Tests fail due to code bugs (fix the code instead)
- Only timestamps or dynamic content changed (check scrubbers)
- Tests fail in CI but pass locally (investigate environment differences first)
-
Make your code changes
-
Run snapshot tests to see differences:
npm run test:verify
-
If the YAML structure intentionally changed, update snapshots:
npm run test:verify -- -u
-
Review ALL snapshot changes carefully - Open each
.snapfile and verify:- Changes are expected and intentional
- No dynamic content (timestamps, random values) leaked through
- YAML structure is valid
- All test cases have matching snapshots
-
Commit the updated snapshot files with your code changes:
git add src/lib/docker-compose/__tests__/__verify__/__snapshots__/ git commit -m "feat: your feature description - Update snapshots for [describe changes] - All snapshot tests pass"
Important: Snapshot files are tracked in version control and must be committed:
*.snapfiles are NOT ignored by.gitignore- CI validates that snapshot files exist before running tests
- All team members must use the same snapshot baseline
The verify.config.json file configures snapshot behavior:
{
"traitParameters": [
{ "name": "config", "extension": "txt" }
],
"scrubbers": [
{
"name": "timestamps",
"regex": "# Generated at: .*",
"replacement": "# Generated at: [FIXED_TIMESTAMP]"
}
],
"directory": "__verify__"
}Scrubbers remove dynamic content from snapshots:
- Timestamps are replaced with fixed values
- Add more scrubbers if you have other dynamic content (paths, random IDs, etc.)
Problem: Tests fail but you didn't change YAML generation logic.
Solutions:
- Check for dynamic content issues - verify scrubbers in
verify.config.json - Check for environment-specific values (OS paths, Node version differences)
- Review the actual diff to understand what changed
Problem: Timestamps or other dynamic content are not being scrubbed.
Solutions:
- Verify
verify.config.jsonhas correct regex patterns - Test the regex:
echo "# Generated at: 2024/01/01" | grep "# Generated at: .*" - Add new scrubbers for other dynamic content
Problem: Local tests pass but CI fails due to path differences.
Solutions:
- Ensure paths are standardized in test inputs
- Add path scrubbers to
verify.config.json:{ "name": "paths", "regex": "/home/[^/]+/", "replacement": "/home/user/" }
Problem: CI fails with "snapshot files not found".
Solutions:
- Verify snapshot files are committed:
git ls-files src/lib/docker-compose/__tests__/__verify__/__snapshots__/ - Check
.gitignoredoesn't exclude*.snapor__snapshots__directories - Ensure snapshots are included in your commit/PR
Problem: All snapshot tests fail in CI but pass locally.
Solutions:
- Check CI Node.js version matches local version
- Verify dependencies are installed correctly:
npm ci - Review CI logs for specific differences
- Ensure snapshot files are present in the branch
The CI pipeline (.github/workflows/ci.yml) includes:
- Verify Snapshot Files - Explicit check that snapshot files exist
- Build - TypeScript compilation
- Test - Full test suite including snapshot verification
- PR Comment - Automated test results on pull requests
- name: Verify Snapshot Files
run: |
SNAPSHOT_DIR="src/lib/docker-compose/__tests__/__verify__/__snapshots__"
if [ ! -d "$SNAPSHOT_DIR" ]; then
echo "Error: Snapshot directory not found"
exit 1
fi
SNAPSHOT_COUNT=$(find "$SNAPSHOT_DIR" -name "*.snap" | wc -l)
echo "Found $SNAPSHOT_COUNT snapshot file(s)"
ls -la "$SNAPSHOT_DIR"/*.snapCI automatically comments on PRs with test results:
- Success: All tests passed
- Failure: Check logs for details
- Review Snapshot Changes: Always review snapshot diffs before committing
- Document Changes: Include snapshot updates in commit messages
- Run Full Suite: Run
npm testbefore pushing to ensure all tests pass - Check CI Results: Monitor CI runs to catch environment-specific issues
- Keep Scrubbers Updated: Add scrubbers for any new dynamic content
- Small Focused Changes: Keep commits focused to make snapshot reviews easier
- Team Communication: Notify team when snapshot structure changes intentionally
Current test counts:
- Unit Tests: ~62 tests
- BDD Tests: ~40 tests
- Snapshot Tests: ~23 tests
- Total: ~125 tests
Run coverage reports:
npm run test:coverage