Skip to content

Commit 34501b1

Browse files
author
Luca Forstner
committed
test(e2e): Add E2E tests for transactions in React test app
1 parent 6eaff53 commit 34501b1

File tree

1 file changed

+94
-1
lines changed

1 file changed

+94
-1
lines changed

packages/e2e-tests/test-applications/standard-frontend-react/tests/behaviour-test.spec.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,105 @@ test('Sends an exception to Sentry', async ({ page }) => {
3636
`https://sentry.io/api/0/projects/${SENTRY_TEST_ORG_SLUG}/${SENTRY_TEST_PROJECT}/events/${exceptionEventId}/`,
3737
{ headers: { Authorization: `Bearer ${authToken}` } },
3838
);
39-
clearTimeout(timeout);
4039
expect(response?.status).toBe(200);
4140
break;
4241
} catch (e) {
4342
lastErrorResponse = e;
4443
await new Promise(resolve => setTimeout(resolve, EVENT_POLLING_RETRY_INTERVAL));
4544
}
4645
}
46+
47+
clearTimeout(timeout);
48+
});
49+
50+
test('Sends a pageload transaction to Sentry', async ({ page }) => {
51+
await page.goto('/');
52+
53+
const recordedTransactionsHandle = await page.waitForFunction(() => {
54+
if (window.recordedTransactions && window.recordedTransactions?.length >= 1) {
55+
return window.recordedTransactions;
56+
} else {
57+
return undefined;
58+
}
59+
});
60+
const recordedTransactionEventIds = (await recordedTransactionsHandle.jsonValue()) as string[];
61+
62+
const timeout = setTimeout(() => {
63+
throw new Error('Timeout reached while polling events.');
64+
}, EVENT_POLLING_TIMEOUT);
65+
66+
let hadPageLoadTransaction = false;
67+
68+
await Promise.all(
69+
recordedTransactionEventIds.map(async (transactionEventId, i) => {
70+
while (true) {
71+
try {
72+
const response = await axios.get(
73+
`https://sentry.io/api/0/projects/${SENTRY_TEST_ORG_SLUG}/${SENTRY_TEST_PROJECT}/events/${transactionEventId}/`,
74+
{ headers: { Authorization: `Bearer ${authToken}` } },
75+
);
76+
expect(response?.status).toBe(200);
77+
if (response.data.contexts.trace.op === 'pageload') {
78+
hadPageLoadTransaction = true;
79+
}
80+
break;
81+
} catch (e) {
82+
await new Promise(resolve => setTimeout(resolve, EVENT_POLLING_RETRY_INTERVAL));
83+
}
84+
}
85+
}),
86+
);
87+
88+
clearTimeout(timeout);
89+
90+
expect(hadPageLoadTransaction).toBe(true);
91+
});
92+
93+
test.only('Sends a navigation transaction to Sentry', async ({ page }) => {
94+
await page.goto('/');
95+
96+
// Give pageload transaction time to finish
97+
page.waitForTimeout(4000);
98+
99+
const linkElement = page.locator('id=navigation');
100+
await linkElement.click();
101+
102+
const recordedTransactionsHandle = await page.waitForFunction(() => {
103+
if (window.recordedTransactions && window.recordedTransactions?.length >= 2) {
104+
return window.recordedTransactions;
105+
} else {
106+
return undefined;
107+
}
108+
});
109+
const recordedTransactionEventIds = (await recordedTransactionsHandle.jsonValue()) as string[];
110+
111+
const timeout = setTimeout(() => {
112+
throw new Error('Timeout reached while polling events.');
113+
}, EVENT_POLLING_TIMEOUT);
114+
115+
let hadPageNavigationTransaction = false;
116+
117+
await Promise.all(
118+
recordedTransactionEventIds.map(async (transactionEventId, i) => {
119+
while (true) {
120+
try {
121+
const response = await axios.get(
122+
`https://sentry.io/api/0/projects/${SENTRY_TEST_ORG_SLUG}/${SENTRY_TEST_PROJECT}/events/${transactionEventId}/`,
123+
{ headers: { Authorization: `Bearer ${authToken}` } },
124+
);
125+
expect(response?.status).toBe(200);
126+
if (response.data.contexts.trace.op === 'pageload') {
127+
hadPageNavigationTransaction = true;
128+
}
129+
break;
130+
} catch (e) {
131+
await new Promise(resolve => setTimeout(resolve, EVENT_POLLING_RETRY_INTERVAL));
132+
}
133+
}
134+
}),
135+
);
136+
137+
clearTimeout(timeout);
138+
139+
expect(hadPageNavigationTransaction).toBe(true);
47140
});

0 commit comments

Comments
 (0)