test: raise unit coverage to ~99.9% and enforce thresholds#64
Merged
Conversation
Add unit tests across the CLI (commands, core, generators, prompts, utils, and the entry dispatcher), bringing line coverage from 23% to 99.9%. Tests are co-located *.test.ts, follow the repo's dependency-injection style, and mock external boundaries (@clack/prompts, fs, child_process, network, keyring) without changing any source. Add Vitest coverage thresholds (lines/statements 99, functions 99, branches 95) as a regression floor. The remaining uncovered lines are unreachable branches (a private multiline-env helper in the docker generator).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A large testing push that takes CLI unit coverage from 23.2% to 99.9% lines, then adds Vitest coverage thresholds so the level is enforced going forward.
Stacked on top of #63 (the coverage-badge PR); this PR is targeted at that branch so the diff is only the test work. Merge #63 first, or retarget to
mainafter it lands.Coverage
552 tests (548 passing, 4 pre-existing skipped e2e). 44 new/updated
*.test.tsfiles covering every command, core module, generator, prompt, util, and the entry dispatcher.Approach
*.test.tsand follow the repo's existing dependency-injection style (e.g.setBackendForTesting, injected clients/fetch, thefakeClientpattern).@clack/prompts,fs,child_process, network (fetch),@napi-rs/keyring, andadm-zip(via real in-memory zip fixtures).process.exit(throw-to-short-circuit) and assert user-facing output, request shapes, and exit codes.src/index.ts(which runsmain()at import) is tested by mocking every command module and re-importing per argv scenario withvi.resetModules().vitest.config.tsthreshold block.Thresholds (the enforced "limits")
Added to
vitest.config.ts, set just below current numbers as a regression floor:npm run coverage(and therefore the pre-commit hook from #63) now fails if coverage drops below these.Remaining uncovered (7 lines)
All are genuinely unreachable branches, documented rather than papered over:
src/generators/docker/docker.ts(5 lines): a private multiline-env helper; values reaching it come fromparseEnvString/secret generators and can never contain a newline.??/optional-chaining default operands whose lines are fully covered.Checks
npm run coveragepasses with thresholds enforced (exit 0)npm run buildpasses