Skip to content

Commit 6797044

Browse files
authored
test(solidstart): Add client performance e2e tests (#12895)
1 parent d67df35 commit 6797044

File tree

6 files changed

+122
-4
lines changed

6 files changed

+122
-4
lines changed

dev-packages/e2e-tests/test-applications/solidstart/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
"clean": "pnpx rimraf node_modules pnpm-lock.yaml .vinxi .output",
66
"dev": "NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi dev",
77
"build": "vinxi build",
8-
"preview": "HOST=localhost PORT=3030 NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi start",
8+
"//": [
9+
"We are using `vinxi dev` to start the server because `vinxi start` is experimental and ",
10+
"doesn't correctly resolve modules for @sentry/solidstart/solidrouter.",
11+
"This is currently not an issue outside of our repo. See: https://github.com/nksaraf/vinxi/issues/177"
12+
],
13+
"preview": "HOST=localhost PORT=3030 NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi dev",
914
"test:prod": "TEST_ENV=production playwright test",
1015
"test:build": "pnpm install && npx playwright install && pnpm build",
1116
"test:assert": "pnpm test:prod"
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import { withSentryRouterRouting } from '@sentry/solidstart/solidrouter';
12
import { MetaProvider, Title } from '@solidjs/meta';
23
import { Router } from '@solidjs/router';
34
import { FileRoutes } from '@solidjs/start/router';
45
import { Suspense } from 'solid-js';
56

7+
const SentryRouter = withSentryRouterRouting(Router);
8+
69
export default function App() {
710
return (
8-
<Router
11+
<SentryRouter
912
root={props => (
1013
<MetaProvider>
1114
<Title>SolidStart - with Vitest</Title>
@@ -14,6 +17,6 @@ export default function App() {
1417
)}
1518
>
1619
<FileRoutes />
17-
</Router>
20+
</SentryRouter>
1821
);
1922
}

dev-packages/e2e-tests/test-applications/solidstart/src/entry-client.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// @refresh reload
22
import * as Sentry from '@sentry/solidstart';
3+
import { solidRouterBrowserTracingIntegration } from '@sentry/solidstart/solidrouter';
34
import { StartClient, mount } from '@solidjs/start/client';
45

56
Sentry.init({
67
// We can't use env variables here, seems like they are stripped
78
// out in production builds.
89
dsn: 'https://[email protected]/1337',
910
environment: 'qa', // dynamic sampling bias to keep transactions
10-
integrations: [Sentry.browserTracingIntegration()],
11+
integrations: [solidRouterBrowserTracingIntegration()],
1112
tunnel: 'http://localhost:3031/', // proxy server
1213
// Performance Monitoring
1314
tracesSampleRate: 1.0, // Capture 100% of the transactions

dev-packages/e2e-tests/test-applications/solidstart/src/routes/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ export default function Home() {
1111
<li>
1212
<A href="/client-error">Client error</A>
1313
</li>
14+
<li>
15+
<A id="navLink" href="/users/5">
16+
User 5
17+
</A>
18+
</li>
19+
<li>
20+
<A id="navLinkUserBack" href="/users/6">
21+
User 6
22+
</A>
23+
</li>
1424
</ul>
1525
</>
1626
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useParams } from '@solidjs/router';
2+
3+
export default function User() {
4+
const params = useParams();
5+
return <div>User ID: {params.id}</div>;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('sends a pageload transaction', async ({ page }) => {
5+
const transactionPromise = waitForTransaction('solidstart', async transactionEvent => {
6+
return transactionEvent?.transaction === '/' && transactionEvent.contexts?.trace?.op === 'pageload';
7+
});
8+
9+
await page.goto('/');
10+
const pageloadTransaction = await transactionPromise;
11+
12+
expect(pageloadTransaction).toMatchObject({
13+
contexts: {
14+
trace: {
15+
op: 'pageload',
16+
origin: 'auto.pageload.browser',
17+
},
18+
},
19+
transaction: '/',
20+
transaction_info: {
21+
source: 'url',
22+
},
23+
});
24+
});
25+
26+
test('sends a navigation transaction', async ({ page }) => {
27+
const transactionPromise = waitForTransaction('solidstart', async transactionEvent => {
28+
return transactionEvent?.transaction === '/users/5' && transactionEvent.contexts?.trace?.op === 'navigation';
29+
});
30+
31+
await page.goto(`/`);
32+
await page.locator('#navLink').click();
33+
const navigationTransaction = await transactionPromise;
34+
35+
expect(navigationTransaction).toMatchObject({
36+
contexts: {
37+
trace: {
38+
op: 'navigation',
39+
origin: 'auto.navigation.solid.solidrouter',
40+
},
41+
},
42+
transaction: '/users/5',
43+
transaction_info: {
44+
source: 'url',
45+
},
46+
});
47+
});
48+
49+
test('updates the transaction when using the back button', async ({ page }) => {
50+
// Solid Router sends a `-1` navigation when using the back button.
51+
// The sentry solidRouterBrowserTracingIntegration tries to update such
52+
// transactions with the proper name once the `useLocation` hook triggers.
53+
const navigationTxnPromise = waitForTransaction('solidstart', async transactionEvent => {
54+
return transactionEvent?.transaction === '/users/6' && transactionEvent.contexts?.trace?.op === 'navigation';
55+
});
56+
57+
await page.goto(`/`);
58+
await page.locator('#navLinkUserBack').click();
59+
const navigationTxn = await navigationTxnPromise;
60+
61+
expect(navigationTxn).toMatchObject({
62+
contexts: {
63+
trace: {
64+
op: 'navigation',
65+
origin: 'auto.navigation.solid.solidrouter',
66+
},
67+
},
68+
transaction: '/users/6',
69+
transaction_info: {
70+
source: 'url',
71+
},
72+
});
73+
74+
const backNavigationTxnPromise = waitForTransaction('solidstart', async transactionEvent => {
75+
return transactionEvent?.transaction === '/' && transactionEvent.contexts?.trace?.op === 'navigation';
76+
});
77+
78+
await page.goBack();
79+
const backNavigationTxn = await backNavigationTxnPromise;
80+
81+
expect(backNavigationTxn).toMatchObject({
82+
contexts: {
83+
trace: {
84+
op: 'navigation',
85+
origin: 'auto.navigation.solid.solidrouter',
86+
},
87+
},
88+
transaction: '/',
89+
transaction_info: {
90+
source: 'url',
91+
},
92+
});
93+
});

0 commit comments

Comments
 (0)