test: add vitest unit testing infrastructure and initial test suite#6
Merged
Conversation
- 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
edcc710 to
ec3808b
Compare
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.
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.tswithWxtVitest()plugin for WXT globals/aliasestestandtest:watchscripts in package.jsonpnpm teststep added to both CI and release workflowsTests (33 total, co-located with source)
github-api.test.ts(24) — link header parsing, pagination, auth headers, error classification, cache integrationstorage.test.ts(5) — cache key format, TTL expiration, storage round-tripworkflow-filter.test.ts(4) — URL pattern matching, repo path parsingRefactors for Testability:
parseLinkHeader,fetchAllWorkflows,GitHubApiErrorfrom github-api.tscacheKeyfrom storage.tsparseRepo,ACTIONS_PATTERNfrom workflow-filter.ts; parameterizedparseRepoto accept pathname argGitHubApiError.statusreadonlyTesting Notes
fakeBrowserfromwxt/testingfor storage (in-memory, no browser)vi.stubGlobal("fetch", ...)for API mocking, zero external deps