Skip to content

test(nuxt): cover the client plugin's pages-router instrumentation - #25348

Open
61465 wants to merge 1 commit into
getsentry:developfrom
61465:fix/nuxt-client-plugin-tests
Open

61465 wants to merge 1 commit into
getsentry:developfrom
61465:fix/nuxt-client-plugin-tests

Conversation

@61465

@61465 61465 commented Oct 14, 2026

Copy link
Copy Markdown

Summary

Closes #13813.

Fills in the Nuxt client-plugin unit tests requested by @mydea. Picks up where the dormant draft #24583 (@vansh-nagar, inactive since 2026-02; pinged by @JPeer264 on 2026-10-12 with no reply within the stated window) left off and extends it to all five code paths in packages/nuxt/src/runtime/plugins/sentry.client.ts.

What this covers

  1. Vue route provider setup (_INTERNAL_createVueRouteProvider → setRouteProvider)
    • Installs when getClient() returns a client, $router is on the Nuxt app, and no provider is set
    • Respects a user-supplied provider (does not override)
    • Skips without an initialized client
    • Skips without a $router on the Nuxt app
  2. browserTracingIntegration
    • Adds with { router, routeLabel: 'path' } on the happy path
    • Skips without an initialized client
    • Skips without a $router
  3. app:created hook — Vue integration
    • Calls vueIntegration with attachErrorHandler: false and the live Vue app
    • Handles the client-torn-down case (second getClient() returns undefined)
  4. app:error hook — status-code filtering
    • Nuxt error + 4xx/3xx status → skip
    • Nuxt error + 5xx → report
    • Non-Nuxt error → report regardless of status shape
  5. vue:error hook
    • Forwards { error, instance, info } to reportNuxtError

Pattern

Mocks mirror packages/nuxt/test/runtime/hooks/captureErrorHook.test.ts:

  • vi.hoisted(() => vi.fn()) for cross-module mock refs
  • vi.mock(import('…'), async importOriginal => …) for @sentry/core, @sentry/vue, nuxt/app
  • vi.spyOn(utils, 'reportNuxtError') for the local ../utils module

Pure vitest, no native dependencies. Runs under the existing yarn test command in packages/nuxt/.

Local verification

Syntax parse via tsc --noEmit --skipLibCheck on the test file passes (only "Cannot find module" warnings remain for workspace packages, which CI resolves via yarn install). I was unable to materialise the Yarn/npm workspace node_modules locally on my Windows + Node 24 shell (ETARGET on whatwg-url@^17.2.0, same error reported upstream in jsdom's current chain), so I'm relying on your CI matrix to confirm the suite is green across the vitest + jsdom environment configured in packages/nuxt/vite.config.ts.

Notes

  • All five code paths were taken straight from the current src/runtime/plugins/sentry.client.ts; happy to re-shape the test file structure if the preferred house style here is one describe per public behaviour rather than per source-code region.
  • @vansh-nagar's draft is credited above; if they prefer to carry this over I'll close this PR and move my coverage there as review comments.

cc @mydea + @JPeer264 — thanks for the pre-blessing on #13813 and for keeping the issue open.

🤖 Used Claude Code for the test scaffolding and to cross-check the mock shapes against existing nuxt tests; every assertion was signed off by me on content.

Fills in the Nuxt client-plugin unit tests requested in getsentry#13813.
Supersedes the dormant draft in getsentry#24583 (last activity 2026-02; author
pinged 2026-10-12 by @JPeer264 with no reply).

Covers the five code paths in `src/runtime/plugins/sentry.client.ts`:
  1. Vue route provider setup (installs, respects user provider, skips
     without client, skips without `$router`)
  2. `browserTracingIntegration` (adds with router+path label, skips on
     no client, skips on no router)
  3. `app:created` hook — `vueIntegration` with
     `attachErrorHandler: false`, including client-torn-down path
  4. `app:error` hook — 4xx/3xx status-code skip for Nuxt errors, 5xx
     and non-Nuxt errors still reported
  5. `vue:error` hook — forwards error + instance + info to
     `reportNuxtError`

Follows the mock pattern already used in
`captureErrorHook.test.ts` (vi.hoisted + vi.mock(importOriginal) +
spyOn on local utils). Pure vitest, no native deps.

Refs getsentry#13813.
@61465
61465 requested a review from a team as a code owner October 14, 2026 03:25
@61465
61465 requested review from nicohrubec and s1gr1d and removed request for a team October 14, 2026 03:25
@github-actions github-actions Bot added the external PR from an external contributor label Oct 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Nuxt pages router unit tests

1 participant