Repository navigation
test(nuxt): Cover pages router instrumentation - #24583
vansh-nagar wants to merge 1 commit into
Conversation
s1gr1d
left a comment
There was a problem hiding this comment.
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).
Fixes getsentry#13813 Co-Authored-By: OpenAI Codex <codex@openai.com>
0149c63 to
1a80479
Compare
|
This PR is still in draft, do you plan to still add something to it? |
|
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 |
|
Closing, as there is no response |
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>
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>
…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>
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