Skip to content

Unit tests with vitest#15

Merged
azizbecha merged 1 commit into
mainfrom
chore/add-tests
May 3, 2026
Merged

Unit tests with vitest#15
azizbecha merged 1 commit into
mainfrom
chore/add-tests

Conversation

@azizbecha
Copy link
Copy Markdown
Owner

Summary

Vitest as a devDependency; 35 specs across four targets the audit identified.

File What it covers
tests/duration.test.ts formatDuration thresholds (ms / s / m / h), negative clamp, fractional flooring
tests/pluralize.test.ts singular/plural for 1, 0, n; custom plural; negative
tests/snapshotParser.test.ts flat lists, no-label rows, escaped-quote labels, depth from leading whitespace (spaces + tabs), ignored lines, dedupe, CRLF, empty input
tests/scriptParser.test.ts parseScript (blank / comment-only, context and env directives, 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

  • Extracted parseSnapshotRefs to src/runners/snapshotParser.ts (vscode-free) so tests can import without mocking the vscode module. src/services/snapshotIndex.ts re-exports it for existing callers — no breaking change.

Wiring

  • package.json: test (one-shot, runs vitest run) and test:watch scripts
  • .github/workflows/ci.yml: npm test runs between format:check and compile
  • .vscodeignore: excludes tests/, .github/, .oxlintrc.json, .oxfmtrc.json, vitest.config.ts from the published .vsix

Test plan

  • npm test — 35/35 pass locally
  • npm run lint — 0 warnings, 0 errors
  • npm run format:check — clean
  • npm run compile — clean
  • npm run package — 1.04 MB / 248 files (no test files leak in)
  • CI runs the new step on this PR

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.
@azizbecha azizbecha merged commit 6029d83 into main May 3, 2026
1 check passed
@azizbecha azizbecha deleted the chore/add-tests branch May 3, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant