Skip to content

feat(browser): add render helper for vitest browser mode#1725

Open
yamachi4416 wants to merge 1 commit into
nuxt:mainfrom
yamachi4416:feat-improve-vitest-browser-mode
Open

feat(browser): add render helper for vitest browser mode#1725
yamachi4416 wants to merge 1 commit into
nuxt:mainfrom
yamachi4416:feat-improve-vitest-browser-mode

Conversation

@yamachi4416

@yamachi4416 yamachi4416 commented Jun 16, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

Added a render helper wrapping vitest-browser-vue with a suspense helper, to be used in Vitest Browser Mode.

@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1725
npm i https://pkg.pr.new/vitest-environment-nuxt@1725

commit: 9392515

@yamachi4416 yamachi4416 force-pushed the feat-improve-vitest-browser-mode branch from 2059d23 to a041a16 Compare June 17, 2026 14:03
@yamachi4416 yamachi4416 changed the title feat(browser): add vitest browser testing helper feat(browser): add render helper for vitest browser mode Jun 17, 2026
@yamachi4416 yamachi4416 marked this pull request as ready for review June 17, 2026 15:01
@yamachi4416 yamachi4416 requested a review from danielroe as a code owner June 17, 2026 15:01
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc31503b-bea0-48cb-b9cd-6b821d589128

📥 Commits

Reviewing files that changed from the base of the PR and between fa70fad and 9392515.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (33)
  • examples/app-vitest-browser/app.vue
  • examples/app-vitest-browser/app/app.vue
  • examples/app-vitest-browser/app/components/Header.vue
  • examples/app-vitest-browser/app/components/MyCounter.vue
  • examples/app-vitest-browser/app/components/MyHello.vue
  • examples/app-vitest-browser/app/composables/useCounter.ts
  • examples/app-vitest-browser/app/composables/useHelloApi.ts
  • examples/app-vitest-browser/app/layouts/default.vue
  • examples/app-vitest-browser/app/pages/components.vue
  • examples/app-vitest-browser/app/pages/components/counter.vue
  • examples/app-vitest-browser/app/pages/components/hello.vue
  • examples/app-vitest-browser/app/pages/index.vue
  • examples/app-vitest-browser/nuxt.config.ts
  • examples/app-vitest-browser/server/api/hello.get.ts
  • examples/app-vitest-browser/test/nuxt/components/mock-nuxt-import.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/mount-suspended.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render.vue.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-components-hello.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-index.spec.ts
  • examples/app-vitest-browser/tsconfig.json
  • examples/app-vitest-browser/vitest.config.ts
  • examples/app-vitest-workspace/app3/nuxt.config.ts
  • examples/app-vitest-workspace/app3/test/browser/render.spec.ts
  • examples/app-vitest-workspace/app3/vitest.browser.config.ts
  • examples/app-vitest-workspace/app3/vitest.config.ts
  • examples/app-vitest-workspace/package.json
  • package.json
  • src/runtime-utils/utils/suspended.ts
  • src/vitest-browser-nuxt/index.ts
  • src/vitest-browser-nuxt/pure.ts
  • tsdown.config.ts
💤 Files with no reviewable changes (1)
  • examples/app-vitest-browser/app.vue
✅ Files skipped from review due to trivial changes (3)
  • examples/app-vitest-browser/app/pages/index.vue
  • examples/app-vitest-browser/tsconfig.json
  • examples/app-vitest-workspace/app3/vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (29)
  • tsdown.config.ts
  • examples/app-vitest-browser/app/composables/useHelloApi.ts
  • examples/app-vitest-workspace/app3/nuxt.config.ts
  • examples/app-vitest-browser/app/components/MyHello.vue
  • examples/app-vitest-browser/test/nuxt/components/render.vue.spec.ts
  • examples/app-vitest-browser/app/composables/useCounter.ts
  • examples/app-vitest-browser/vitest.config.ts
  • examples/app-vitest-workspace/app3/vitest.browser.config.ts
  • examples/app-vitest-browser/app/layouts/default.vue
  • examples/app-vitest-browser/test/nuxt/pages/render-index.spec.ts
  • examples/app-vitest-browser/app/components/Header.vue
  • examples/app-vitest-browser/app/pages/components/counter.vue
  • examples/app-vitest-browser/app/pages/components.vue
  • examples/app-vitest-browser/nuxt.config.ts
  • examples/app-vitest-browser/test/nuxt/components/mount-suspended.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts
  • examples/app-vitest-browser/app/app.vue
  • src/vitest-browser-nuxt/pure.ts
  • examples/app-vitest-browser/app/components/MyCounter.vue
  • examples/app-vitest-browser/test/nuxt/components/render.spec.ts
  • examples/app-vitest-workspace/app3/test/browser/render.spec.ts
  • examples/app-vitest-browser/app/pages/components/hello.vue
  • examples/app-vitest-browser/server/api/hello.get.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-components-hello.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/mock-nuxt-import.spec.ts
  • src/runtime-utils/utils/suspended.ts
  • examples/app-vitest-workspace/package.json
  • package.json
  • src/vitest-browser-nuxt/index.ts

📝 Walkthrough

Walkthrough

This PR introduces a new vitest-browser-nuxt module in src/vitest-browser-nuxt/ that provides a render function for Nuxt components in Vitest browser mode. The function wraps components via the existing wrapperSuspended utility (which gains an optional stubRouterLink flag) and integrates cleanup into the Vitest page object. New export paths, type mappings, and build entries are registered for this module. The examples/app-vitest-browser app is restructured into a multi-page Nuxt app with composables, a server API endpoint, a default layout, and multiple pages. The example's Vitest config is updated to use the new setup file, and browser-mode test suites are added covering component rendering, composable mocking, fetch integration, and full-page navigation. Workspace app3 receives a parallel browser test project configuration.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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
Title check ✅ Passed The title 'feat(browser): add render helper for vitest browser mode' is clear, specific, and accurately describes the main change—adding a new render helper for Vitest Browser Mode.
Description check ✅ Passed The description explains that a render helper wrapping 'vitest-browser-vue' with a suspense helper was added for Vitest Browser Mode, which aligns with the changeset.
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 unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/app-vitest-browser/app/pages/components/hello.vue`:
- Line 3: The `name` computed property is read-only (getter-only) but is used
with `v-model` on line 11, which requires a writable binding. Modify the `name`
computed property to include a setter function that handles updates to the
value, or alternatively refactor to use a separate `ref` for tracking the name
state while initializing its value from `route.query.name` to maintain the
initial synchronization. The computed property with a setter approach would
allow `v-model` updates to be properly handled while maintaining the route query
synchronization logic.

In `@examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts`:
- Around line 7-10: The registerEndpoint() call that registers the `/api/hello`
endpoint lacks a corresponding teardown mechanism, leaving the endpoint
registered in the shared registry after the test completes. This causes
cross-test state leakage where the endpoint remains registered for subsequent
tests. Add an afterEach() cleanup hook that unregisters or clears the
`/api/hello` endpoint registration after each test runs to ensure a clean state
between tests and prevent order-dependent test failures.

In `@examples/app-vitest-browser/test/nuxt/components/render.spec.ts`:
- Line 27: The assertion in the render spec test is too strict by matching the
exact JSON string with specific quote marks and spacing in getByText(). Replace
the exact string match with a regex pattern or flexible matcher that tolerates
various whitespace and formatting variations while still validating that the
buildAssetsDir key and /_nuxt/ value are present in the rendered output. This
will prevent false test failures from non-functional formatting changes to the
JSON serialization.

In `@examples/app-vitest-workspace/app3/test/browser/render.spec.ts`:
- Around line 25-27: The 'can rerender' test is currently using `page.render()`
to set up the initial render, which duplicates the page-specific render path
already tested elsewhere and prevents the actual testing of the
`render().rerender()` pattern. Replace the `page.render()` call in this test
with the standard `render()` function to properly initialize the component,
allowing the subsequent `rerender()` call to test the non-page rerender
functionality as intended.

In `@examples/app-vitest-workspace/package.json`:
- Around line 25-27: The package.json is missing an explicit declaration of the
`playwright` dependency which is required as a peer dependency by
`@vitest/browser-playwright@4.1.8`. Although `playwright-core` is present, it
does not satisfy the peer dependency requirement. Add `"playwright": "1.60.0"`
to the devDependencies object in package.json, placing it alongside the existing
entries like `@vitest/browser-playwright`, `happy-dom`, and `playwright-core` to
ensure the required peer dependency is explicitly declared.

In `@package.json`:
- Around line 54-58: The typesVersions entries for "vitest-browser-nuxt" and
"vitest-browser-nuxt/pure" in package.json are pointing to root-level
declaration files (./dist/index.d.mts and ./dist/pure.d.mts), but these files
are actually generated in nested locations under the vitest-browser-nuxt
directory structure. Update the paths for both the "vitest-browser-nuxt" and
"vitest-browser-nuxt/pure" entries in the typesVersions object to point to the
correct nested locations where the declaration files are actually generated
during the build process.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50490d1a-d8d8-4898-8910-8b8851b22b5c

📥 Commits

Reviewing files that changed from the base of the PR and between e1a0f63 and a041a16.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (33)
  • examples/app-vitest-browser/app.vue
  • examples/app-vitest-browser/app/app.vue
  • examples/app-vitest-browser/app/components/Header.vue
  • examples/app-vitest-browser/app/components/MyCounter.vue
  • examples/app-vitest-browser/app/components/MyHello.vue
  • examples/app-vitest-browser/app/composables/useCounter.ts
  • examples/app-vitest-browser/app/composables/useHelloApi.ts
  • examples/app-vitest-browser/app/layouts/default.vue
  • examples/app-vitest-browser/app/pages/components.vue
  • examples/app-vitest-browser/app/pages/components/counter.vue
  • examples/app-vitest-browser/app/pages/components/hello.vue
  • examples/app-vitest-browser/app/pages/index.vue
  • examples/app-vitest-browser/nuxt.config.ts
  • examples/app-vitest-browser/server/api/hello.get.ts
  • examples/app-vitest-browser/test/nuxt/components/mock-nuxt-import.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/mount-suspended.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render.vue.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-components-hello.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-index.spec.ts
  • examples/app-vitest-browser/tsconfig.json
  • examples/app-vitest-browser/vitest.config.ts
  • examples/app-vitest-workspace/app3/nuxt.config.ts
  • examples/app-vitest-workspace/app3/test/browser/render.spec.ts
  • examples/app-vitest-workspace/app3/vitest.browser.config.ts
  • examples/app-vitest-workspace/app3/vitest.config.ts
  • examples/app-vitest-workspace/package.json
  • package.json
  • src/runtime-utils/utils/suspended.ts
  • src/vitest-browser-nuxt/index.ts
  • src/vitest-browser-nuxt/pure.ts
  • tsdown.config.ts
💤 Files with no reviewable changes (1)
  • examples/app-vitest-browser/app.vue

Comment thread examples/app-vitest-browser/app/pages/components/hello.vue Outdated
Comment thread examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts Outdated
Comment thread examples/app-vitest-browser/test/nuxt/components/render.spec.ts Outdated
Comment thread examples/app-vitest-workspace/app3/test/browser/render.spec.ts
Comment thread examples/app-vitest-workspace/package.json
Comment thread package.json Outdated
@yamachi4416 yamachi4416 force-pushed the feat-improve-vitest-browser-mode branch 2 times, most recently from 1242c5f to 5ebdb4a Compare June 17, 2026 15:33
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@yamachi4416 yamachi4416 force-pushed the feat-improve-vitest-browser-mode branch from 5ebdb4a to fb97146 Compare June 17, 2026 23:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/app-vitest-browser/server/api/hello.get.ts`:
- Around line 4-5: The getQuery function does not enforce runtime type
validation, so the name parameter can be undefined, a string, or an array of
strings at runtime, but the code assumes it is always a string. Add a
normalization step after extracting name from the query object to handle these
cases: check if name is undefined or an array, and either provide a default
value (like an empty string or "Guest"), extract the first element if it is an
array, or trim/validate the string value. This ensures the return statement in
the hello.get.ts endpoint always receives a properly handled name value.

In `@package.json`:
- Around line 21-22: The export paths for the "./vitest-browser-nuxt" and
"./vitest-browser-nuxt/pure" subpaths are pointing to dist directories instead
of source directories, which breaks workspace and local development imports
before build artifacts are generated. Change both export paths from
"./dist/vitest-browser-nuxt/..." to "./src/vitest-browser-nuxt/..." to match the
pattern of other top-level exports, allowing the publishConfig.exports to handle
the dist paths for published versions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a58936ad-9640-45f3-ac90-9a68f7d81022

📥 Commits

Reviewing files that changed from the base of the PR and between 1242c5f and fb97146.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (33)
  • examples/app-vitest-browser/app.vue
  • examples/app-vitest-browser/app/app.vue
  • examples/app-vitest-browser/app/components/Header.vue
  • examples/app-vitest-browser/app/components/MyCounter.vue
  • examples/app-vitest-browser/app/components/MyHello.vue
  • examples/app-vitest-browser/app/composables/useCounter.ts
  • examples/app-vitest-browser/app/composables/useHelloApi.ts
  • examples/app-vitest-browser/app/layouts/default.vue
  • examples/app-vitest-browser/app/pages/components.vue
  • examples/app-vitest-browser/app/pages/components/counter.vue
  • examples/app-vitest-browser/app/pages/components/hello.vue
  • examples/app-vitest-browser/app/pages/index.vue
  • examples/app-vitest-browser/nuxt.config.ts
  • examples/app-vitest-browser/server/api/hello.get.ts
  • examples/app-vitest-browser/test/nuxt/components/mock-nuxt-import.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/mount-suspended.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render.vue.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-components-hello.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-index.spec.ts
  • examples/app-vitest-browser/tsconfig.json
  • examples/app-vitest-browser/vitest.config.ts
  • examples/app-vitest-workspace/app3/nuxt.config.ts
  • examples/app-vitest-workspace/app3/test/browser/render.spec.ts
  • examples/app-vitest-workspace/app3/vitest.browser.config.ts
  • examples/app-vitest-workspace/app3/vitest.config.ts
  • examples/app-vitest-workspace/package.json
  • package.json
  • src/runtime-utils/utils/suspended.ts
  • src/vitest-browser-nuxt/index.ts
  • src/vitest-browser-nuxt/pure.ts
  • tsdown.config.ts
💤 Files with no reviewable changes (1)
  • examples/app-vitest-browser/app.vue
✅ Files skipped from review due to trivial changes (1)
  • examples/app-vitest-browser/vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (29)
  • examples/app-vitest-browser/test/nuxt/components/mount-suspended.spec.ts
  • examples/app-vitest-browser/app/composables/useCounter.ts
  • examples/app-vitest-workspace/app3/vitest.browser.config.ts
  • examples/app-vitest-browser/nuxt.config.ts
  • examples/app-vitest-browser/app/components/Header.vue
  • examples/app-vitest-browser/tsconfig.json
  • examples/app-vitest-browser/app/layouts/default.vue
  • examples/app-vitest-browser/test/nuxt/pages/render-index.spec.ts
  • src/runtime-utils/utils/suspended.ts
  • examples/app-vitest-browser/test/nuxt/components/render.spec.ts
  • examples/app-vitest-browser/app/pages/index.vue
  • examples/app-vitest-browser/app/components/MyCounter.vue
  • examples/app-vitest-workspace/app3/vitest.config.ts
  • examples/app-vitest-workspace/app3/nuxt.config.ts
  • examples/app-vitest-browser/app/app.vue
  • examples/app-vitest-browser/app/components/MyHello.vue
  • tsdown.config.ts
  • examples/app-vitest-browser/app/composables/useHelloApi.ts
  • examples/app-vitest-workspace/app3/test/browser/render.spec.ts
  • examples/app-vitest-browser/app/pages/components.vue
  • examples/app-vitest-browser/app/pages/components/hello.vue
  • examples/app-vitest-browser/test/nuxt/components/render.vue.spec.ts
  • examples/app-vitest-browser/test/nuxt/components/render-with-fetch.spec.ts
  • examples/app-vitest-browser/test/nuxt/pages/render-components-hello.spec.ts
  • examples/app-vitest-browser/app/pages/components/counter.vue
  • examples/app-vitest-workspace/package.json
  • src/vitest-browser-nuxt/pure.ts
  • src/vitest-browser-nuxt/index.ts
  • examples/app-vitest-browser/test/nuxt/components/mock-nuxt-import.spec.ts

Comment thread examples/app-vitest-browser/server/api/hello.get.ts Outdated
Comment thread package.json Outdated
@yamachi4416 yamachi4416 marked this pull request as draft June 18, 2026 00:00
@yamachi4416 yamachi4416 force-pushed the feat-improve-vitest-browser-mode branch from fb97146 to fa70fad Compare June 18, 2026 08:56
@yamachi4416 yamachi4416 marked this pull request as ready for review June 18, 2026 09:02
@yamachi4416 yamachi4416 force-pushed the feat-improve-vitest-browser-mode branch from fa70fad to 9392515 Compare June 18, 2026 09:35
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