|
| 1 | +import type { Route } from '@playwright/test'; |
| 2 | +import { expect } from '@playwright/test'; |
| 3 | +import type { SessionContext } from '@sentry/types'; |
| 4 | + |
| 5 | +import { sentryTest } from '../../../utils/fixtures'; |
| 6 | +import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers'; |
| 7 | + |
| 8 | +sentryTest('should start a new session on pageload.', async ({ getLocalTestPath, page }) => { |
| 9 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 10 | + const session = await getFirstSentryEnvelopeRequest<SessionContext>(page, url); |
| 11 | + |
| 12 | + expect(session).toBeDefined(); |
| 13 | + expect(session.init).toBe(true); |
| 14 | + expect(session.errors).toBe(0); |
| 15 | + expect(session.status).toBe('ok'); |
| 16 | +}); |
| 17 | + |
| 18 | +sentryTest('should start a new session with navigation.', async ({ getLocalTestPath, page, browserName }) => { |
| 19 | + // Navigations get CORS error on Firefox and WebKit as we're using `file://` protocol. |
| 20 | + if (browserName !== 'chromium') { |
| 21 | + sentryTest.skip(); |
| 22 | + } |
| 23 | + |
| 24 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 25 | + await page.route('**/foo', (route: Route) => route.fulfill({ path: `${__dirname}/dist/index.html` })); |
| 26 | + |
| 27 | + const initSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url); |
| 28 | + |
| 29 | + await page.click('#navigate'); |
| 30 | + |
| 31 | + const newSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url); |
| 32 | + |
| 33 | + expect(newSession).toBeDefined(); |
| 34 | + expect(newSession.init).toBe(true); |
| 35 | + expect(newSession.errors).toBe(0); |
| 36 | + expect(newSession.status).toBe('ok'); |
| 37 | + expect(newSession.sid).toBeDefined(); |
| 38 | + expect(initSession.sid).not.toBe(newSession.sid); |
| 39 | +}); |
0 commit comments