Skip to content

feat(test): Vitest suite for lib/wordpress/* (pilot for #63)#86

Merged
JohnRDOrazio merged 1 commit into
mainfrom
feat/vitest-lib-wordpress
May 14, 2026
Merged

feat(test): Vitest suite for lib/wordpress/* (pilot for #63)#86
JohnRDOrazio merged 1 commit into
mainfrom
feat/vitest-lib-wordpress

Conversation

@JohnRDOrazio
Copy link
Copy Markdown
Member

@JohnRDOrazio JohnRDOrazio commented May 14, 2026

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

File Coverage Purpose
lib/wordpress/client.test.ts 100% stmt / 95% branch wpQuery happy path, all three error branches (non-OK HTTP, non-JSON body, GraphQL errors[]), forwarding of revalidate / tags / draft+token to fetch's next options
lib/wordpress/api.test.ts 64% stmt / 74% func LOCALE_MAP coverage (via observable GraphQL call args), leading-slash slug rule, EN-fallback in getPage/getPostBySlug, mapping correctness for the four sitemap-adjacent helpers (getAllPages, getPostsForSitemap, getProjectsForSitemap, getChildPages) that were the #57/#59 hot spots, error-fallback shape for each

34 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-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/**
  • .github/workflows/test-nextjs.yml: non-blocking (continue-on-error: true) Vitest run on PRs that touch lib/**, package.json, or vitest.config.ts — per the spec's "land tests, watch them stabilize, flip the gate in a follow-up" guidance

Conventions established by this pilot (carry into PR 2/3)

  • Tests co-located with source (*.test.ts next to *.ts), matching the spec
  • Mocking: vi.stubGlobal('fetch') for client.test.ts, vi.mock('./client') for api.test.ts
  • Coverage reported but not thresholded
  • CI workflow is non-blocking; flipping to required is a separate follow-up issue

Test plan

  • npm test — 34/34 pass
  • npm run test:coverage — coverage report printed
  • npm run lint — clean
  • npm run build — clean (no type regressions from adding .test.ts files to the tree)
  • CI workflow runs green on the PR

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

    • Added comprehensive unit tests for WordPress GraphQL API helpers covering locale mapping, page/post retrieval, and sitemap generation.
    • Added test suite validating GraphQL client request handling, error cases, and authentication.
  • Chores

    • Integrated Vitest test runner with coverage reporting for automated testing.
    • Added npm scripts: test, test:watch, and test:coverage.
  • Documentation

    • Updated development guide with test execution commands and scope information.

Review Change Stack

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f882f19b-1d55-4463-987b-d8fe0893d9c0

📥 Commits

Reviewing files that changed from the base of the PR and between d62be2d and a587870.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .github/workflows/test-nextjs.yml
  • AGENTS.md
  • eslint.config.mjs
  • lib/wordpress/api.test.ts
  • lib/wordpress/client.test.ts
  • package.json
  • vitest.config.ts

📝 Walkthrough

Walkthrough

This 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.

Changes

Vitest Framework and Tests

Layer / File(s) Summary
Vitest configuration and npm scripts
vitest.config.ts, package.json
Configures Vitest to run tests in Node environment from lib/**/*.test.ts, enables v8 coverage for lib/wordpress/**, and adds test, test:watch, and test:coverage npm scripts with dev dependencies.
WordPress GraphQL client tests
lib/wordpress/client.test.ts
Tests wpQuery covering successful JSON responses returning data payload, POST request formation with query and variables, header/option forwarding including next.revalidate and tags, draft-mode forcing revalidate to 0 with Authorization bearer tokens, and error handling for non-OK HTTP responses, non-JSON content, and GraphQL error arrays.
WordPress API helper tests
lib/wordpress/api.test.ts
Tests locale-to-language-code mapping with EN fallback, getPage and getPostBySlug with localized/EN fallback behavior and error swallowing, and sitemap helpers (getAllPages, getPostsForSitemap, getProjectsForSitemap, getChildPages) covering URI derivation, available locale aggregation, filtering hidden posts, date/modified fallback, and slug selection logic.
CI workflow and documentation
.github/workflows/test-nextjs.yml, AGENTS.md, eslint.config.mjs
Adds GitHub Actions workflow triggering on lib/** and related changes, running npm ci and npm test with non-blocking behavior and concurrency cancellation; updates developer documentation with test command descriptions; excludes coverage artifacts from ESLint.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰 With whiskers twitching, tests now run,
And coverage flows like morning sun,
Where queries dance and helpers play,
Vitest brings us brighter day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(test): Vitest suite for lib/wordpress/* (pilot for #63)' accurately summarizes the main change: adding a Vitest test suite for the WordPress library code as a pilot project.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vitest-lib-wordpress

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 46 complexity · 4 duplication

Metric Results
Complexity 46
Duplication 4

View in Codacy

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.

@JohnRDOrazio JohnRDOrazio merged commit 762dd10 into main May 14, 2026
11 checks passed
@JohnRDOrazio JohnRDOrazio deleted the feat/vitest-lib-wordpress branch May 14, 2026 16:02
JohnRDOrazio added a commit that referenced this pull request May 14, 2026
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>
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