feat(test): Vitest suite for lib/wordpress/* (pilot for #63)#86
Conversation
First of three planned test suites per #63's design spec. Vitest is chosen as the pilot because it's pure-add — no production code refactor — so it validates the spec's scope assumptions before committing to the larger PHPUnit and bats efforts. Covers: - lib/wordpress/client.test.ts (100% stmt / 95% branch / 100% func) — wpQuery happy path, all error branches (non-OK HTTP, non-JSON body, GraphQL errors[]), and forwarding of revalidate / tags / draft+token through to fetch's next options. - lib/wordpress/api.test.ts (64% stmt / 74% func) — LOCALE_MAP coverage (via observable GraphQL call args), the leading-slash slug rule and '/' special case, EN-fallback in getPage and getPostBySlug, mapping correctness for the four sitemap-adjacent helpers (getAllPages, getPostsForSitemap, getProjectsForSitemap, getChildPages) that were the hot spots in #57 / #59, and the error-fallback shape (return [] / null) for each of those helpers. The uncovered helpers in api.ts (getPosts, getProjects, getProject, getAcademicCollaboration, getSponsors) are out of scope for the pilot — they have no historical bug record and no non-trivial mapping logic. A follow-up can extend coverage if regressions surface there. Plumbing: - vitest + @vitest/coverage-v8 as devDependencies - vitest.config.ts at repo root (node env, v8 coverage scoped to lib/wordpress/**/*.ts) - npm scripts: test, test:watch, test:coverage - eslint.config.mjs: ignore coverage/** so generated HTML doesn't trigger an "unused eslint-disable" warning on lint - .github/workflows/test-nextjs.yml: non-blocking (continue-on-error) Vitest run on PRs that touch lib/**, package.json, or vitest.config PHPUnit and bats suites land separately per #63's per-stack-PR rollout. Refs #63. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR establishes Vitest as the test runner for the Next.js data layer, adding configuration, comprehensive test suites for WordPress GraphQL helpers, CI integration, and documentation. ChangesVitest Framework and Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 46 |
| Duplication | 4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Two new plans under docs/superpowers/plans/ complete the rollout described in the test-suites design spec (2026-05-02-test-suites-design.md): - 2026-05-02-test-suites-phpunit.md (PR 2): scaffold composer + PHPUnit + Brain Monkey + Mockery for wordpress/plugins/cdcf-redis-translations and wordpress/themes/cdcf-headless. Mechanical refactor of REST route closures into named handlers, then four test classes covering the maintenance, process-queue, enqueue-translation fallback, and theme relationship handlers. - 2026-05-02-test-suites-bats.md (PR 3): extract worker helpers from scripts/cdcf_queue_worker.sh into a sibling lib file, vendor bats-core as a submodule, and add five .bats files covering in_maintenance, queue_is_empty (new from #85), parse_processed, should_run_daily_tasks, and process_one. Both plans carry forward the lessons from PR 1 (#86, Vitest pilot): scope coverage by motivation rather than line target, mock one abstraction layer down, keep CI non-blocking at first. The two plans touch disjoint paths so they can be executed in parallel worktrees. Refs #63. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
First of three planned test suites for #63 (no test runner configured in this repo). Pilot because it's pure-add — no production-code refactor required — so it validates the spec's scope before committing to the larger PHPUnit and bats efforts.
Summary
lib/wordpress/client.test.tswpQueryhappy path, all three error branches (non-OK HTTP, non-JSON body, GraphQLerrors[]), forwarding ofrevalidate/tags/draft+tokentofetch'snextoptionslib/wordpress/api.test.tsLOCALE_MAPcoverage (via observable GraphQL call args), leading-slash slug rule, EN-fallback ingetPage/getPostBySlug, mapping correctness for the four sitemap-adjacent helpers (getAllPages,getPostsForSitemap,getProjectsForSitemap,getChildPages) that were the #57/#59 hot spots, error-fallback shape for each34 tests, all passing locally; total runtime ~200ms.
Uncovered helpers in
api.ts(getPosts,getProjects,getProject,getAcademicCollaboration,getSponsors) are intentionally out of scope for the pilot — they have no historical bug record and no non-trivial mapping logic. A follow-up can extend if regressions surface there.Plumbing
vitest+@vitest/coverage-v8as devDependenciesvitest.config.tsat repo root (node env, v8 coverage scoped tolib/wordpress/**/*.ts)npmscripts:test,test:watch,test:coverageeslint.config.mjs: ignorecoverage/**.github/workflows/test-nextjs.yml: non-blocking (continue-on-error: true) Vitest run on PRs that touchlib/**,package.json, orvitest.config.ts— per the spec's "land tests, watch them stabilize, flip the gate in a follow-up" guidanceConventions established by this pilot (carry into PR 2/3)
*.test.tsnext to*.ts), matching the specvi.stubGlobal('fetch')forclient.test.ts,vi.mock('./client')forapi.test.tsTest plan
npm test— 34/34 passnpm run test:coverage— coverage report printednpm run lint— cleannpm run build— clean (no type regressions from adding.test.tsfiles to the tree)Out of scope
PHPUnit suite for the WP plugin and theme, and bats suite for the bash worker — both land separately per #63's per-stack-PR rollout.
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
Chores
test,test:watch, andtest:coverage.Documentation