Unit tests with vitest#15
Merged
Merged
Conversation
Vitest as a devDependency. New tests/ directory covers the four audit-identified pure-function targets: - duration.test.ts — formatDuration thresholds (ms/s/m/h), negatives, fractional clamp - pluralize.test.ts — 1 vs n, custom plurals, negatives - snapshotParser.test.ts — flat list, no-label rows, escaped-quote labels, depth from leading whitespace (spaces + tabs), ignored lines, dedupe, empty input, CRLF - scriptParser.test.ts — parseScript (blank/comment-only, context and env directives, action line numbers, comment stripping outside strings, escaped quotes inside quoted tokens, CRLF) + interpolate (basic, inside quotes, default fallback, defined beats default, missing → empty, non-vars untouched) + dequote (strip + unescape, unquoted passthrough, unbalanced quote) 35 specs total, ~130ms runtime. To make parseSnapshotRefs importable without VS Code at runtime, extracted it to src/runners/snapshotParser.ts (no vscode imports). src/services/snapshotIndex.ts re-exports it for existing callers. CI runs `npm test` between format:check and compile. package.json scripts: test (one-shot), test:watch. .vscodeignore excludes tests, .github, lint/format/test configs from the published vsix.
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
Vitest as a devDependency; 35 specs across four targets the audit identified.
tests/duration.test.tsformatDurationthresholds (ms / s / m / h), negative clamp, fractional flooringtests/pluralize.test.tstests/snapshotParser.test.tstests/scriptParser.test.tsparseScript(blank / comment-only,contextandenvdirectives, action line numbers, comment stripping with quoted strings, CRLF, escaped quotes) +interpolate(basic, inside quotes, default fallback, override beats default, missing → empty) +dequote(strip + unescape, passthrough, unbalanced)35 specs · ~130 ms.
Refactor
parseSnapshotRefstosrc/runners/snapshotParser.ts(vscode-free) so tests can import without mocking thevscodemodule.src/services/snapshotIndex.tsre-exports it for existing callers — no breaking change.Wiring
package.json:test(one-shot, runsvitest run) andtest:watchscripts.github/workflows/ci.yml:npm testruns betweenformat:checkandcompile.vscodeignore: excludestests/,.github/,.oxlintrc.json,.oxfmtrc.json,vitest.config.tsfrom the published.vsixTest plan
npm test— 35/35 pass locallynpm run lint— 0 warnings, 0 errorsnpm run format:check— cleannpm run compile— cleannpm run package— 1.04 MB / 248 files (no test files leak in)