Skip to content

test(nuxt): Cover pages router instrumentation - #24583

Closed
vansh-nagar wants to merge 1 commit into
getsentry:developfrom
vansh-nagar:fix/nuxt-pages-router-tests
Closed

vansh-nagar wants to merge 1 commit into
getsentry:developfrom
vansh-nagar:fix/nuxt-pages-router-tests

Conversation

@vansh-nagar

Copy link
Copy Markdown

The Nuxt client plugin's pages-router integration had no direct unit coverage after the earlier SDK-level BrowserTracing assertion was removed.

This adds focused checks that the initialized client receives BrowserTracing with Nuxt's router and path-based route labels, while an uninitialized client does not create the integration.

Fixes #13813

@s1gr1d s1gr1d self-assigned this Sep 29, 2026

@s1gr1d s1gr1d left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR!

We already cover pages-router instrumentation in the nuxt-4 E2E app. The remaining value of a unit test here is covering the branches that E2E doesn't cover: a test that browserTracingIntegration is not called and addIntegration is only called for the vue integration path (similar to 'does not create router instrumentation without an initialized client'). But we need coverage for if (sentryClient && '$router' in nuxtApp).

@s1gr1d s1gr1d added the external PR from an external contributor label Sep 29, 2026
Fixes getsentry#13813

Co-Authored-By: OpenAI Codex <codex@openai.com>
@vansh-nagar
vansh-nagar force-pushed the fix/nuxt-pages-router-tests branch from 0149c63 to 1a80479 Compare September 29, 2026 18:36
@s1gr1d

s1gr1d commented Oct 2, 2026

Copy link
Copy Markdown
Member

This PR is still in draft, do you plan to still add something to it?

@JPeer264

Copy link
Copy Markdown
Member

Hey @vansh-nagar are you still planning to work on this? If we can start review your PR you can move it to "Ready for review". If there is no activity it's better for us to close it, to keep the opened PRs low

@JPeer264

Copy link
Copy Markdown
Member

Closing, as there is no response

@JPeer264 JPeer264 closed this Oct 19, 2026
61465 added a commit to 61465/sentry-javascript that referenced this pull request Oct 22, 2026
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.

Signed-off-by: Abd Alrahaman <abdarahman10555@gmail.com>
61465 added a commit to 61465/sentry-javascript that referenced this pull request Oct 30, 2026
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.

Signed-off-by: Abd Alrahaman <abdarahman10555@gmail.com>
nicohrubec added a commit that referenced this pull request Nov 2, 2026
…25348)

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

---------

Signed-off-by: Abd Alrahaman <abdarahman10555@gmail.com>
Co-authored-by: Nicolas Hrubec <nico.hrubec@sentry.io>
Co-authored-by: OpenAI GPT-6 <codex@openai.com>
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

3 participants