Skip to content

test: add vitest unit testing infrastructure and initial test suite#6

Merged
cheefbird merged 10 commits into
mainfrom
test/basic-vitest-implementation
Mar 13, 2026
Merged

test: add vitest unit testing infrastructure and initial test suite#6
cheefbird merged 10 commits into
mainfrom
test/basic-vitest-implementation

Conversation

@cheefbird
Copy link
Copy Markdown
Owner

@cheefbird cheefbird commented Mar 12, 2026

Context

Project had no tests. This sets up vitest with WXT's testing plugin, adds unit tests for all business logic modules, and gates CI + release on passing tests. Minor refactors to export internal functions for testability.

Changes Made

Infra

  • vitest.config.ts with WxtVitest() plugin for WXT globals/aliases
  • test and test:watch scripts in package.json
  • pnpm test step added to both CI and release workflows

Tests (33 total, co-located with source)

  • github-api.test.ts (24) — link header parsing, pagination, auth headers, error classification, cache integration
  • storage.test.ts (5) — cache key format, TTL expiration, storage round-trip
  • workflow-filter.test.ts (4) — URL pattern matching, repo path parsing

Refactors for Testability:

  • Exported parseLinkHeader, fetchAllWorkflows, GitHubApiError from github-api.ts
  • Exported cacheKey from storage.ts
  • Exported parseRepo, ACTIONS_PATTERN from workflow-filter.ts; parameterized parseRepo to accept pathname arg
  • Made GitHubApiError.status readonly

Testing Notes

  • All 33 pass in ~450ms
  • fakeBrowser from wxt/testing for storage (in-memory, no browser)
  • vi.stubGlobal("fetch", ...) for API mocking, zero external deps
  • Svelte component mock in workflow-filter tests avoids jsdom dependency

@cheefbird cheefbird self-assigned this Mar 12, 2026
- export parseLinkHeader, fetchAllWorkflows, GitHubApiError from github-api.ts
- export cacheKey from storage.ts
- export parseRepo, ACTIONS_PATTERN from workflow-filter.ts
- parseLinkHeader, GitHubApiError, fetchAllWorkflows, getWorkflows
- Cache TTL expiration and storage round-trip
- URL parsing and actions pattern matching
- add readonly to GitHubApiError.status to prevent post-construction mutation
- parseRepo now accepts optional pathname arg, defaults to location.pathname
- add vi.unstubAllGlobals() cleanup to prevent global stub leakage between tests
- add tests for MAX_PAGES pagination limit, HTTP 500, and JSON parse failure
- simplify parseRepo tests to use parameterized function instead of stubbing location
@cheefbird cheefbird force-pushed the test/basic-vitest-implementation branch from edcc710 to ec3808b Compare March 13, 2026 02:17
@cheefbird cheefbird merged commit 95d9d73 into main Mar 13, 2026
4 checks passed
@cheefbird cheefbird deleted the test/basic-vitest-implementation branch March 13, 2026 02:26
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