test(react-grab): unit-test Next runtime detection + base path - #502
Closed
aidenybai wants to merge 1 commit into
Closed
test(react-grab): unit-test Next runtime detection + base path#502aidenybai wants to merge 1 commit into
aidenybai wants to merge 1 commit into
Conversation
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).
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
4 tasks
Owner
Author
|
Superseded by #510, which consolidates all the test-coverage PRs into one. Commits preserved there. |
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.
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.tsvia thenext-server-framespath always hit the empty branch). Tested in isolation in node with a stubbeddocument.__NEXT_DATA__(Pages Router) andnextjs-portal(App Router dev overlay) detection, the no-document and no-marker negatives, and the memoize/shouldRevalidatecache contract.basePathprefix (/app/_next/…→/app), the root/_next/and missing-script empty cases, and first-call memoization. Each branch re-imports a fresh module viavi.resetModules()since the module-level cache has no reset hook.Test plan
pnpm test:unit— 98 passed (was 89)pnpm typecheckcleanpnpm lintcleanpnpm format:check— only flags pre-existingcore/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: stubsdocumentto assert Pages Router (__NEXT_DATA__) and App Router dev overlay (nextjs-portal) detection, no-document/no-marker negatives, and memoization untilshouldRevalidateclears the cache.get-next-base-path: stubs a/_next/scriptsrcto assert configuredbasePathprefix extraction, root and missing-script empty results, and first-call memoization. Tests usevi.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-runtimeandget-next-base-pathinreact-grab, using a stubbeddocumentto 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.