Skip to content

chore: core unit tests for shared + main modules#54

Merged
aicayzer merged 5 commits into
mainfrom
chore/core-tests
May 12, 2026
Merged

chore: core unit tests for shared + main modules#54
aicayzer merged 5 commits into
mainfrom
chore/core-tests

Conversation

@aicayzer
Copy link
Copy Markdown
Owner

Summary

Adds a focused test pass over the calculation, parsing, and disk-read surfaces. 78 tests, sub-second runtime, no new dependencies.

  • aggregates.test.ts — overview, daily seeding, trend gaps (the W19 regression that the bug-fix PR addressed), vocab carry-forward, streaks, mode percentages, bucket granularities, word-frequency stopword filter, filler roll-up, heatmap
  • range.test.tsfilterByRange bounds + invalid-datetime tolerance
  • text-metrics.test.tstokenise, normalisePhrases, buildFillers (word-boundary, multi-word, ordering)
  • scanner.test.ts — tmpdir fixtures covering valid / malformed / no-meta / non-directory entries, zero-duration → 0 wpm, missing root path, sort order, filler threading
  • config.test.ts — electron mocked via vi.hoisted; defaults, fillerWords migration paths, setConfig round-trip, resetConfig, isPathValid, resolveRecordingsPath parent-promotion, isPathInsideHome
  • useFilteredAggregates.test.ts — exports pickBucketBy + datasetSpanDays so they're testable without React; the hook itself is glue

Skipped (with reasoning in the plan): IPC handlers (thin glue), protocol/watcher/updater (Electron-bound), Zustand stores, components, Playwright.

vitest.config.ts gains the @shared / @renderer aliases so source files keep using them under test.

Test plan

  • pnpm typecheck / pnpm lint / pnpm format:check / pnpm test all green locally
  • CI green on macos-14

aicayzer added 5 commits May 12, 2026 20:02
- add fixture-based suite for computeAll: overview, daily seeding,
  trend gaps (the W19 regression), vocab carry-forward, streaks,
  mode pct sum, bucketBy granularities, streakWindowDays, word
  frequency stopword filter, filler summary roll-up, heatmap cell
- mirror tsconfig path aliases (@shared, @Renderer) in vitest config
  so source files keep using the alias under test
- filterByRange: open window passthrough, from/to bounds, invalid
  datetime tolerance
- tokenise: stopword filter, length floor, empty input
- normalisePhrases: case-insensitive dedupe, non-string rejection,
  first-seen ordering
- buildFillers: word-boundary matching, substring rejection,
  multi-word + whitespace tolerance, breakdown invariants
- valid recording → parsed Recording with derived metrics
- malformed JSON folders counted as errors
- folders without meta.json counted as skipped
- non-directory root entries ignored
- zero-duration → 0 wpm (not Infinity)
- non-existent root path returns empty without throwing
- output sorted newest-first by datetime
- configured filler list flows through to fillerBreakdown
- mock electron.app.getPath via vi.hoisted so each test runs against a
  fresh tmpdir
- getConfig: defaults, fillerWords injection, empty-array preservation,
  additive migration, malformed-JSON fallback
- setConfig round-trips through disk
- resetConfig wipes back to defaults
- isPathValid: requires a child with meta.json
- resolveRecordingsPath: promotes a SuperWhisper parent to its
  recordings/ subdirectory
- isPathInsideHome: home / outside / null
- export pickBucketBy + datasetSpanDays so they're directly testable
  without rendering the hook (which is glue around computeAll +
  zustand selectors that's already covered upstream)
- pickBucketBy: day for <=29d, week for 30-90d, month beyond
- datasetSpanDays: empty, single recording, multi-recording span,
  invalid datetime tolerance
@aicayzer aicayzer merged commit 50cc5ab into main May 12, 2026
3 checks passed
@aicayzer aicayzer deleted the chore/core-tests branch May 12, 2026 19:08
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