This gives you a detailed, interactive view of code coverage:
npm run test:coverage:viewThis will:
- Run all tests with coverage metrics
- Automatically open the HTML report in your browser
- Show line-by-line coverage highlighting
What to look for:
- 🟢 Green lines = covered by tests
- 🟡 Yellow lines = partially covered
- 🔴 Red lines = not covered
npm run test:coverageShows a summary table:
File | % Stmts | % Branch | % Funcs | % Lines
cryptoRandom.js | 100 | 100 | 100 | 100
entropy.js | 100 | 100 | 100 | 100
generate.js | 100 | 100 | 100 | 100
npm run test:verboseShows each test with pass/fail status, execution time, and clear formatting.
npm run test:watchAutomatically reruns tests when you save files. Perfect for development!
Your current metrics:
✅ Statements: 100% - Every line of code is executed
✅ Branches: 100% - All if/else paths are tested
✅ Functions: 100% - All functions are called
✅ Lines: 100% - All lines are covered
- ✅ 52 tests passing - Good test count for 3 modules
- ✅ 100% coverage - Every line of code is tested
- ✅ Organized structure - Tests grouped by function/feature
- ✅ Descriptive names - Easy to understand what each test does
- ✅ Edge cases included - Invalid inputs, boundary conditions
- ✅ Error handling tested - Checking throw behavior
- ✅ No console errors - Clean test output
tests/
├── unit/
│ ├── cryptoRandom.test.js (11 tests)
│ ├── entropy.test.js (14 tests)
│ └── generate.test.js (22 tests)
└── README.md
- Tests: 11
- Coverage: 100%
- What's tested:
- Valid range checking (0 to maxExclusive)
- Invalid inputs (negative, zero, exceeds limit)
- Distribution randomness
- Boundary conditions
- Tests: 14
- Coverage: 100%
- What's tested:
- Correct entropy calculations
- Edge cases (length 0, charset size 1)
- Password strength scenarios
- Large number handling
- Tests: 22 (most complex function)
- Coverage: 100%
- What's tested:
- Password length accuracy
- Character inclusion (lowercase, uppercase, digits, symbols)
- Character exclusion (when disabled)
- Default parameters
- Randomness & uniqueness
- Error handling (no sets selected)
- All parameter combinations
❌ Low coverage - Below 80% means untested code ❌ Failing tests - Some code isn't working as expected ❌ No edge case tests - Only testing happy path ❌ Duplicate tests - Same test written multiple times ❌ Flaky tests - Tests that sometimes pass, sometimes fail ❌ Poor test names - Can't tell what the test does ❌ Testing internals only - Not testing user-facing behavior
When you run npm run test:coverage:view, you'll see:
- Coverage Summary - Overall percentages
- File List - Click any file to see line-by-line coverage
- Color Coding:
- Green: Covered by at least one test
- Red: Not covered
- Pink: Partially covered (some branches only)
10 ✅ export function generatePassword({
11 ✅ length = 16,
12 ✅ lowerCase = true,
...
(All lines highlighted in green = fully tested)npm test -- --coverage --detectOpenHandlesnpm run test:watchnpm run test:debug
# Then open chrome://inspect in Chromenpm test -- --coverage --bail --detectOpenHandles--bail: Stop on first failure--coverage: Generate coverage reports--detectOpenHandles: Find resource leaks
| Metric | Value | Status |
|---|---|---|
| Test Suites | 3 | ✅ Pass |
| Total Tests | 52 | ✅ Pass |
| Coverage | 100% | ✅ Excellent |
| Statements | 100% | ✅ All covered |
| Branches | 100% | ✅ All paths tested |
| Functions | 100% | ✅ All called |
Verdict: Your test suite is comprehensive and production-ready! 🎉
- View HTML report:
npm run test:coverage:view - Use watch mode while coding:
npm run test:watch - Run full validation before commits:
npm test -- --coverage --detectOpenHandles - Keep coverage at 100% as you add new features
All tests are looking kosher! 👍