test: establish vitest suite, CI, and coverage reporting (44%→83%)#24
Merged
Conversation
These were never surfaced because esbuild strips types without checking;
adding a typecheck step exposed them.
- options.ts: rename top-level `status` to `statusEl` so it no longer
shadows the DOM global `window.status` (a string), which broke
`.className`/`.textContent` access
- pass the generic type arg to `chrome.storage.local.get<T>()` in
service-worker.ts and better-top-repos.ts so results are typed instead
of defaulting to an index signature (which truthy-narrowed to `{}`)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Set up the first batch of tests for the extension, covering the pure page/URL/string logic in src/lib with zero source changes. - vitest + happy-dom; happy-dom's setURL (wrapped in src/test/url.ts) lets page-detect read `location` without refactoring - 35 unit tests across page-detect, page-marker, and utils - scripts: test, test:watch, typecheck - GitHub Actions CI runs typecheck + test + build on PR/push Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
These plan/spec notes for already-shipped features are no longer useful. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The dir holds a shared test helper (setUrl), not test files — the old name read like a tests location next to the co-located *.test.ts files. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop the checked-in editor settings and ignore the dir going forward so local IDE config stays out of the repo. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- service-worker: add a negative case so the token-change guard (area === "local" && "githubToken" in changes) is actually exercised; a non-token local change and a token change in the sync area must leave the session cache intact. - content: export removeFeatureElements and add a test driving the watch-fork-star removal path directly, guarding the original bug where FEATURE_CLASSES listed "bg-wfs-counter-wrap" (the class on GitHub's own counters) and disabling the feature deleted native counts. - release-tab: clone an *active* reference tab so the selected/aria-current stripping logic is no longer a no-op in the tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Enable the @vitest/coverage-v8 provider with text/html/lcov reporters and a `test:coverage` script. Thresholds are set as a floor just below current numbers (stmts 40 / branch 32 / funcs 45 / lines 42) to guard against large regressions and be ratcheted up over time. They only apply under --coverage, so the plain `pnpm test` used in CI stays unaffected. coverage/ is gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ules
Adds tests for the previously-untested modules, lifting coverage from
~44% to ~83% statements / ~87% lines.
Two data seams are mocked:
- Feature modules (pr-branch-names, pr-diff-stats, pr-review-status,
commit-tags, commit-diff-stats, pr-approve-now, watch-fork-star hover)
mock "../lib/github-api" and assert the rendered DOM.
- github-api.ts mocks chrome.runtime.sendMessage; service-worker mocks
fetch (extended to stargazers/watchers/forks, GraphQL reviews/commit
diff stats, and the tags GraphQL success path).
Pure/infra modules covered directly: better-top-repos, file-age-color,
pr-label-position, feature-flags, navigation, early-sort-redirect, options.
options.ts gains a trailing `export {}` so tests can import() it (no
runtime effect). Coverage thresholds raised to a new floor (78/62/78/82).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Background
The project previously had no tests and no CI — every change had to be verified by hand-loading the extension against real GitHub pages. This PR stands up the test infrastructure from scratch, wires up CI and coverage reporting, and raises coverage from ~44% to ~83%.
Overview
1. Test infrastructure
vitest+happy-dom(same toolchain as esbuild; native TS/ESM, no extra transpile)setURL(wrapped insrc/test-utils/url.ts) lets the page-detection logic switchlocationwithout touching sourcetest/test:watch/test:coverage/typecheck2. CI
.github/workflows/ci.yml: runstypecheck+test+buildon PR/push (pinned pnpm major to match local; actions bumped to node24-compatible versions)3. Coverage reporting
@vitest/coverage-v8withtext/html/lcovreporters;coverage/is gitignored--coverageso plainpnpm test/CI is unaffected — meant to be ratcheted up as coverage grows4. Test coverage (173 tests / 28 files)
Mocked at the right data seam per layer, rather than one blunt approach:
github-apivi.mock(\"../lib/github-api\")with canned data; assert rendered DOMgithub-api→chrome.runtimechrome.runtime.sendMessagefetchfetch+chrome.storage5. Real bugs found and fixed while writing tests
FEATURE_CLASSESlistedbg-wfs-counter-wrap— the class we add to GitHub's own counters — as a removable element, soremoveFeatureElementsranremove()on the native watch/fork/star counts on disable. Fixed to only remove our ownbg-wfs-popupplus a newcleanupWatchForkStarPopup, guarded by an integration test.options.tsFEATURE_KEYSwas missingfeature-pr-collapse-expand: caught by the registry-sync test that keeps the three feature lists aligned.tscactually ran (statusshadowingwindow.status, missing generics onchrome.storage.local.get<T>(), etc.).Quality (not coverage for its own sake)
navigation.ts's non-teardownable module-level listeners.Coverage
Verification
pnpm typecheck→ 0 errorspnpm test→ 28 files / 173 tests passpnpm test:coverage→ meets thresholds (exit 0)pnpm build→ clean, no test files leak intodist/Still lower / optional follow-up
watch-fork-star-popup56%,release-tab74%,pr-collapse-expand/content~72% — the remainder is mostly GitHub's "new experience" DOM branches with diminishing returns; not forced in this PR.🤖 Generated with Claude Code