Skip to content

Commit fbe06f6

Browse files
committed
add integration test for deprecated API
1 parent 6f3b143 commit fbe06f6

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
release: '0.1',
8+
// intentionally disabling this, we want to leverage the deprecated hub API
9+
autoSessionTracking: false,
10+
});
11+
12+
// simulate old startSessionTracking behavior
13+
Sentry.getCurrentHub().startSession({ ignoreDuration: true });
14+
Sentry.getCurrentHub().captureSession();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<a id='navigate' href="foo">Navigate</button>
8+
</body>
9+
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)