Skip to content

test(react-grab): unit-test Next runtime detection + base path - #502

Closed
aidenybai wants to merge 1 commit into
mainfrom
test/next-runtime-unit-coverage
Closed

test(react-grab): unit-test Next runtime detection + base path#502
aidenybai wants to merge 1 commit into
mainfrom
test/next-runtime-unit-coverage

Conversation

@aidenybai

@aidenybai aidenybai commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

The e2e coverage run skips the Next fixture, leaving these document-driven helpers structurally untested (is-next-project-runtime.ts ~20%, get-next-base-path.ts via the next-server-frames path always hit the empty branch). Tested in isolation in node with a stubbed document.

  • is-next-project-runtime.ts: __NEXT_DATA__ (Pages Router) and nextjs-portal (App Router dev overlay) detection, the no-document and no-marker negatives, and the memoize/shouldRevalidate cache contract.
  • get-next-base-path.ts: the configured-basePath prefix (/app/_next/…/app), the root /_next/ and missing-script empty cases, and first-call memoization. Each branch re-imports a fresh module via vi.resetModules() since the module-level cache has no reset hook.

Test plan

  • pnpm test:unit — 98 passed (was 89)
  • pnpm typecheck clean
  • pnpm lint clean
  • pnpm format:check — only flags pre-existing core/index.tsx (untouched)

Note

Low Risk
Test-only changes with no production code modifications.

Overview
Adds unit tests only for two DOM-dependent Next.js helpers that were lightly covered because e2e skips the Next fixture.

is-next-project-runtime: stubs document to assert Pages Router (__NEXT_DATA__) and App Router dev overlay (nextjs-portal) detection, no-document/no-marker negatives, and memoization until shouldRevalidate clears the cache.

get-next-base-path: stubs a /_next/ script src to assert configured basePath prefix extraction, root and missing-script empty results, and first-call memoization. Tests use vi.resetModules() and fresh dynamic imports because the module cache has no reset hook.

Reviewed by Cursor Bugbot for commit 5ddaa05. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Add unit tests for is-next-project-runtime and get-next-base-path in react-grab, using a stubbed document to run in Node. Covers Pages/App Router markers, no-document/no-marker and missing-script cases, basePath extraction (including root /_next/), and memoization/revalidation behavior.

Written for commit 5ddaa05. Summary will update on new commits.

Review in cubic

The e2e suite skips the Next fixture, so these document-driven helpers
were structurally untested. Stub `document` in node to cover their branches:

- is-next-project-runtime.ts: __NEXT_DATA__ (Pages) and nextjs-portal (App
  Router) detection, the no-document and no-marker negatives, and the
  memoize/revalidate cache contract.
- get-next-base-path.ts: the configured-basePath prefix, the root /_next/
  and missing-script empty cases, and first-call memoization (fresh module
  per branch since the cache has no reset hook).
@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-grab-storybook Ready Ready Preview, Comment Jun 28, 2026 11:20am
react-grab-website Ready Ready Preview, Comment Jun 28, 2026 11:20am

@pkg-pr-new

pkg-pr-new Bot commented Jun 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@react-grab/cli@502
npm i https://pkg.pr.new/grab@502
npm i https://pkg.pr.new/react-grab@502

commit: 5ddaa05

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@aidenybai

Copy link
Copy Markdown
Owner Author

Superseded by #510, which consolidates all the test-coverage PRs into one. Commits preserved there.

@aidenybai aidenybai closed this Jun 29, 2026
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