|
| 1 | +import { expect, test } from '@nuxt/test-utils/playwright'; |
| 2 | +import { waitForError } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test.describe('client-side errors', async () => { |
| 5 | + test('captures error thrown on click', async ({ page }) => { |
| 6 | + const errorPromise = waitForError('nuxt-3-dynamic-import', async errorEvent => { |
| 7 | + return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Nuxt-3 E2E test app'; |
| 8 | + }); |
| 9 | + |
| 10 | + await page.goto(`/client-error`); |
| 11 | + await page.locator('#errorBtn').click(); |
| 12 | + |
| 13 | + const error = await errorPromise; |
| 14 | + |
| 15 | + expect(error.transaction).toEqual('/client-error'); |
| 16 | + expect(error).toMatchObject({ |
| 17 | + exception: { |
| 18 | + values: [ |
| 19 | + { |
| 20 | + type: 'Error', |
| 21 | + value: 'Error thrown from Nuxt-3 E2E test app', |
| 22 | + mechanism: { |
| 23 | + handled: false, |
| 24 | + }, |
| 25 | + }, |
| 26 | + ], |
| 27 | + }, |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + test('shows parametrized route on button error', async ({ page }) => { |
| 32 | + const errorPromise = waitForError('nuxt-3-dynamic-import', async errorEvent => { |
| 33 | + return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Param Route Button'; |
| 34 | + }); |
| 35 | + |
| 36 | + await page.goto(`/test-param/1234`); |
| 37 | + await page.locator('#errorBtn').click(); |
| 38 | + |
| 39 | + const error = await errorPromise; |
| 40 | + |
| 41 | + expect(error.sdk.name).toEqual('sentry.javascript.nuxt'); |
| 42 | + expect(error.transaction).toEqual('/test-param/:param()'); |
| 43 | + expect(error.request.url).toMatch(/\/test-param\/1234/); |
| 44 | + expect(error).toMatchObject({ |
| 45 | + exception: { |
| 46 | + values: [ |
| 47 | + { |
| 48 | + type: 'Error', |
| 49 | + value: 'Error thrown from Param Route Button', |
| 50 | + mechanism: { |
| 51 | + handled: false, |
| 52 | + }, |
| 53 | + }, |
| 54 | + ], |
| 55 | + }, |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + test('page is still interactive after client error', async ({ page }) => { |
| 60 | + const error1Promise = waitForError('nuxt-3-dynamic-import', async errorEvent => { |
| 61 | + return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Nuxt-3 E2E test app'; |
| 62 | + }); |
| 63 | + |
| 64 | + await page.goto(`/client-error`); |
| 65 | + await page.locator('#errorBtn').click(); |
| 66 | + |
| 67 | + const error1 = await error1Promise; |
| 68 | + |
| 69 | + const error2Promise = waitForError('nuxt-3-dynamic-import', async errorEvent => { |
| 70 | + return errorEvent?.exception?.values?.[0]?.value === 'Another Error thrown from Nuxt-3 E2E test app'; |
| 71 | + }); |
| 72 | + |
| 73 | + await page.locator('#errorBtn2').click(); |
| 74 | + |
| 75 | + const error2 = await error2Promise; |
| 76 | + |
| 77 | + expect(error1).toMatchObject({ |
| 78 | + exception: { |
| 79 | + values: [ |
| 80 | + { |
| 81 | + type: 'Error', |
| 82 | + value: 'Error thrown from Nuxt-3 E2E test app', |
| 83 | + mechanism: { |
| 84 | + handled: false, |
| 85 | + }, |
| 86 | + }, |
| 87 | + ], |
| 88 | + }, |
| 89 | + }); |
| 90 | + |
| 91 | + expect(error2).toMatchObject({ |
| 92 | + exception: { |
| 93 | + values: [ |
| 94 | + { |
| 95 | + type: 'Error', |
| 96 | + value: 'Another Error thrown from Nuxt-3 E2E test app', |
| 97 | + mechanism: { |
| 98 | + handled: false, |
| 99 | + }, |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + }); |
| 104 | + }); |
| 105 | +}); |
0 commit comments