Skip to content

Commit b1fe0b6

Browse files
cursoragentclaude
andcommitted
feat(tanstackstart-react): Add E2E test for tunnel route
Add tunnel route and E2E test to verify createSentryTunnelRoute functionality. The test ensures the tunnel endpoint returns 200 and correctly forwards envelopes. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1691509 commit b1fe0b6

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import{createFileRoute}from'@tanstack/react-router';
2+
import{createSentryTunnelRoute}from'@sentry/tanstackstart-react';
3+
4+
exportconstRoute=createFileRoute('/api/tunnel')({
5+
server: createSentryTunnelRoute({
6+
allowedDsns: [process.env.E2E_TEST_DSN||''],
7+
}),
8+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import{expect,test}from'@playwright/test';
2+
import{waitForError}from'@sentry-internal/test-utils';
3+
4+
test('Tunnel route forwards envelopes to Sentry',async({ baseURL })=>{
5+
consterrorEventPromise=waitForError('tanstackstart-react',errorEvent=>{
6+
returnerrorEvent?.exception?.values?.[0]?.value==='Test error for tunnel route';
7+
});
8+
9+
constdsn=process.env.E2E_TEST_DSN||'';
10+
const[protocol,rest]=dsn.split('://');
11+
const[auth,hostAndPath]=rest.split('@');
12+
const[publicKey]=auth.split(':');
13+
const[host, ...pathParts]=hostAndPath.split('/');
14+
constprojectId=pathParts[pathParts.length-1];
15+
16+
constenvelope=[
17+
JSON.stringify({event_id: crypto.randomUUID(),sent_at: newDate().toISOString()}),
18+
JSON.stringify({
19+
type: 'event',
20+
length: 0,
21+
}),
22+
JSON.stringify({
23+
exception: {
24+
values: [
25+
{
26+
type: 'Error',
27+
value: 'Test error for tunnel route',
28+
},
29+
],
30+
},
31+
platform: 'javascript',
32+
sdk: {
33+
name: 'sentry.javascript.tanstackstart-react',
34+
version: '0.0.0',
35+
},
36+
timestamp: Date.now()/1000,
37+
}),
38+
].join('\n');
39+
40+
consttunnelUrl=`${baseURL}/api/tunnel`;
41+
constsentryUrl=`${protocol}://${host}/api/${projectId}/envelope/`;
42+
43+
constresponse=awaitfetch(tunnelUrl,{
44+
method: 'POST',
45+
headers: {
46+
'Content-Type': 'application/x-sentry-envelope',
47+
'X-Sentry-Auth': `Sentry sentry_key=${publicKey}, sentry_version=7`,
48+
},
49+
body: `${sentryUrl}\n${envelope}`,
50+
});
51+
52+
expect(response.status).toBe(200);
53+
54+
consterrorEvent=awaiterrorEventPromise;
55+
56+
expect(errorEvent).toMatchObject({
57+
exception: {
58+
values: [
59+
{
60+
type: 'Error',
61+
value: 'Test error for tunnel route',
62+
},
63+
],
64+
},
65+
});
66+
});

0 commit comments

Comments
 (0)