-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtunnel.test.ts
More file actions
51 lines (39 loc) · 2.08 KB
/
tunnel.test.ts
File metadata and controls
51 lines (39 loc) · 2.08 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
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/test-utils';
const tunnelRouteMode =
process.env.E2E_TEST_TUNNEL_ROUTE_MODE ?? (process.env.E2E_TEST_CUSTOM_TUNNEL_ROUTE === '1' ? 'custom' : 'off');
const expectedTunnelPathMatcher =
tunnelRouteMode === 'static' ? '/monitor' : tunnelRouteMode === 'custom' ? '/custom-monitor' : /^\/[a-z0-9]{8}$/;
test.skip(tunnelRouteMode === 'off', 'Tunnel assertions only run in the tunnel-route variants');
test('Sends client-side errors through the configured tunnel route', async ({ page }) => {
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Sentry Client Test Error';
});
await page.goto('/');
const pageOrigin = new URL(page.url()).origin;
await expect(page.locator('button').filter({ hasText: 'Break the client' })).toBeVisible();
const managedTunnelResponsePromise = page.waitForResponse(response => {
const responseUrl = new URL(response.url());
return (
responseUrl.origin === pageOrigin &&
response.request().method() === 'POST' &&
(typeof expectedTunnelPathMatcher === 'string'
? responseUrl.pathname === expectedTunnelPathMatcher
: expectedTunnelPathMatcher.test(responseUrl.pathname))
);
});
await page.locator('button').filter({ hasText: 'Break the client' }).click();
const managedTunnelResponse = await managedTunnelResponsePromise;
const managedTunnelUrl = new URL(managedTunnelResponse.url());
const errorEvent = await errorEventPromise;
expect(managedTunnelResponse.status()).toBe(200);
expect(managedTunnelUrl.origin).toBe(pageOrigin);
if (typeof expectedTunnelPathMatcher === 'string') {
expect(managedTunnelUrl.pathname).toBe(expectedTunnelPathMatcher);
} else {
expect(managedTunnelUrl.pathname).toMatch(expectedTunnelPathMatcher);
expect(managedTunnelUrl.pathname).not.toBe('/monitor');
}
expect(errorEvent.exception?.values?.[0]?.value).toBe('Sentry Client Test Error');
expect(errorEvent.transaction).toBe('/');
});