-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy patherrors.test.ts
More file actions
124 lines (94 loc) · 3.81 KB
/
errors.test.ts
File metadata and controls
124 lines (94 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
const usesManagedTunnelRoute =
(process.env.E2E_TEST_TUNNEL_ROUTE_MODE ?? 'off') !== 'off' || process.env.E2E_TEST_CUSTOM_TUNNEL_ROUTE === '1';
test.skip(usesManagedTunnelRoute, 'Default e2e suites run only in the proxy variant');
test('Sends client-side error to Sentry with auto-instrumentation', async ({ page }) => {
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Sentry Client Test Error';
});
await page.goto(`/`);
await expect(page.locator('button').filter({ hasText: 'Break the client' })).toBeVisible();
await page.locator('button').filter({ hasText: 'Break the client' }).click();
const errorEvent = await errorEventPromise;
expect(errorEvent).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Sentry Client Test Error',
mechanism: {
handled: false,
},
},
],
},
});
expect(errorEvent.transaction).toBe('/');
});
test('Sends server-side function error to Sentry with auto-instrumentation', async ({ page }) => {
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error';
});
await page.goto(`/`);
await expect(page.locator('button').filter({ hasText: 'Break server function' })).toBeVisible();
await page.locator('button').filter({ hasText: 'Break server function' }).click();
const errorEvent = await errorEventPromise;
expect(errorEvent).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Sentry Server Function Test Error',
mechanism: {
type: 'auto.middleware.tanstackstart.server_function',
handled: false,
},
},
],
},
});
expect(errorEvent.transaction).toEqual(expect.stringContaining('GET /_serverFn/'));
});
test('Sends API route error to Sentry with auto-instrumentation', async ({ page }) => {
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error';
});
await page.goto(`/`);
await expect(page.locator('button').filter({ hasText: 'Break API route' })).toBeVisible();
await page.locator('button').filter({ hasText: 'Break API route' }).click();
const errorEvent = await errorEventPromise;
expect(errorEvent).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Sentry API Route Test Error',
mechanism: {
type: 'auto.middleware.tanstackstart.request',
handled: false,
},
},
],
},
});
expect(errorEvent.transaction).toBe('GET /api/error');
});
// the sentry global middleware does not capture errors from SSR loader errors since they are serialized before they reach the middleware layer
// this test verifies that the error is in fact not sent to Sentry
test('Does not send SSR loader error to Sentry', async ({ baseURL, page }) => {
let errorEventOccurred = false;
waitForError('tanstackstart-react', event => {
if (!event.type && event.exception?.values?.[0]?.value === 'Sentry SSR Test Error') {
errorEventOccurred = true;
}
return event?.transaction === 'GET /ssr-error';
});
const transactionEventPromise = waitForTransaction('tanstackstart-react', transactionEvent => {
return transactionEvent?.transaction === 'GET /ssr-error';
});
await page.goto('/ssr-error');
await transactionEventPromise;
await (await fetch(`${baseURL}/api/flush`)).text();
expect(errorEventOccurred).toBe(false);
});