-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(tanstackstart-react): Set up E2E test application #18358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+362
−0
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
480c145
set up basic e2e test app
nicohrubec cddb81e
start to instrument test app with sentry (not working yet)
nicohrubec 99c2194
server side init works but the client init is never called
nicohrubec fd19ba0
updates but client instrumentation still broken
nicohrubec 4b1d669
dsn did not resolve in the browser not it works
nicohrubec 18f4303
finish basic client side capture exception test
nicohrubec b9855a9
yarn fix
nicohrubec 3171925
use nitro
nicohrubec 39b9ca3
Merge branch 'develop' into nh/add-tanstackstart-react-e2e
nicohrubec 3cf192d
add test: browser calls server function with an error is reported
nicohrubec 860af0e
add test: manual instrumentation works in server routes
nicohrubec d4b97f4
yarn fix
nicohrubec b8f16a3
remove comment
nicohrubec aa5071a
Merge branch 'develop' into nh/add-tanstackstart-react-e2e
nicohrubec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/tanstackstart-react/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
|
|
||
| node_modules | ||
| dist | ||
| dist-ssr | ||
| *.local | ||
|
|
||
| # Editor directories and files | ||
| .vscode/* | ||
| !.vscode/extensions.json | ||
| .idea | ||
| .DS_Store | ||
| *.suo | ||
| *.ntvs* | ||
| *.njsproj | ||
| *.sln | ||
| *.sw? |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/tanstackstart-react/.npmrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @sentry:registry=http://127.0.0.1:4873 | ||
| @sentry-internal:registry=http://127.0.0.1:4873 |
12 changes: 12 additions & 0 deletions
12
dev-packages/e2e-tests/test-applications/tanstackstart-react/instrument.server.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import * as Sentry from '@sentry/tanstackstart-react'; | ||
|
|
||
| Sentry.init({ | ||
| environment: 'qa', // dynamic sampling bias to keep transactions | ||
| dsn: process.env.E2E_TEST_DSN, | ||
| tunnel: `http://localhost:3031/`, // proxy server | ||
| tracesSampleRate: 1, | ||
| transportOptions: { | ||
| // We expect the app to send a lot of events in a short time | ||
| bufferSize: 1000, | ||
| }, | ||
| }); |
38 changes: 38 additions & 0 deletions
38
dev-packages/e2e-tests/test-applications/tanstackstart-react/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "name": "tanstackstart-react", | ||
| "private": true, | ||
| "version": "0.0.1", | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "vite build && cp instrument.server.mjs .output/server", | ||
| "start": "node --import ./.output/server/instrument.server.mjs .output/server/index.mjs", | ||
| "test": "playwright test", | ||
| "clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
| "test:build": "pnpm install && pnpm build", | ||
| "test:assert": "pnpm test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/tanstackstart-react": "latest || *", | ||
| "@tanstack/react-start": "^1.139.12", | ||
| "@tanstack/react-router": "^1.139.12", | ||
| "react": "^19.2.0", | ||
| "react-dom": "^19.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^19.2.0", | ||
| "@types/react-dom": "^19.2.0", | ||
| "@types/node": "^24.10.0", | ||
| "@typescript-eslint/eslint-plugin": "^7.2.0", | ||
| "@typescript-eslint/parser": "^7.2.0", | ||
| "@vitejs/plugin-react-swc": "^3.5.0", | ||
| "typescript": "^5.9.0", | ||
| "vite": "7.2.0", | ||
| "vite-tsconfig-paths": "^5.1.4", | ||
| "nitro": "^3.0.0", | ||
| "@playwright/test": "~1.53.2", | ||
| "@sentry-internal/test-utils": "link:../../../test-utils" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../package.json" | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/tanstackstart-react/playwright.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| const config = getPlaywrightConfig({ | ||
| startCommand: `pnpm start`, | ||
| port: 3000, | ||
| }); | ||
|
|
||
| export default config; |
25 changes: 25 additions & 0 deletions
25
dev-packages/e2e-tests/test-applications/tanstackstart-react/src/router.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import * as Sentry from '@sentry/tanstackstart-react'; | ||
| import { createRouter } from '@tanstack/react-router'; | ||
| import { routeTree } from './routeTree.gen'; | ||
|
|
||
| export const getRouter = () => { | ||
| const router = createRouter({ | ||
| routeTree, | ||
| scrollRestoration: true, | ||
| }); | ||
|
|
||
| if (!router.isServer) { | ||
| Sentry.init({ | ||
| environment: 'qa', // dynamic sampling bias to keep transactions | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.tanstackRouterBrowserTracingIntegration(router)], | ||
| // We recommend adjusting this value in production, or using tracesSampler | ||
| // for finer control | ||
| tracesSampleRate: 1.0, | ||
| release: 'e2e-test', | ||
| tunnel: 'http://localhost:3031/', // proxy server | ||
| }); | ||
| } | ||
|
|
||
| return router; | ||
| }; | ||
42 changes: 42 additions & 0 deletions
42
dev-packages/e2e-tests/test-applications/tanstackstart-react/src/routes/__root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { ReactNode } from 'react'; | ||
| import { Outlet, createRootRoute, HeadContent, Scripts } from '@tanstack/react-router'; | ||
|
|
||
| export const Route = createRootRoute({ | ||
| head: () => ({ | ||
| meta: [ | ||
| { | ||
| charSet: 'utf-8', | ||
| }, | ||
| { | ||
| name: 'viewport', | ||
| content: 'width=device-width, initial-scale=1', | ||
| }, | ||
| { | ||
| title: 'TanStack Start Starter', | ||
| }, | ||
| ], | ||
| }), | ||
| component: RootComponent, | ||
| }); | ||
|
|
||
| function RootComponent() { | ||
| return ( | ||
| <RootDocument> | ||
| <Outlet /> | ||
| </RootDocument> | ||
| ); | ||
| } | ||
|
|
||
| function RootDocument({ children }: Readonly<{ children: ReactNode }>) { | ||
| return ( | ||
| <html> | ||
| <head> | ||
| <HeadContent /> | ||
| </head> | ||
| <body> | ||
| {children} | ||
| <Scripts /> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
17 changes: 17 additions & 0 deletions
17
dev-packages/e2e-tests/test-applications/tanstackstart-react/src/routes/api.error.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import * as Sentry from '@sentry/tanstackstart-react'; | ||
| import { createFileRoute } from '@tanstack/react-router'; | ||
|
|
||
| export const Route = createFileRoute('/api/error')({ | ||
| server: { | ||
| handlers: { | ||
| GET: async () => { | ||
| try { | ||
| throw new Error('Sentry API Route Test Error'); | ||
| } catch (error) { | ||
| Sentry.captureException(error); | ||
| throw error; | ||
andreiborza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
41 changes: 41 additions & 0 deletions
41
dev-packages/e2e-tests/test-applications/tanstackstart-react/src/routes/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { createFileRoute } from '@tanstack/react-router'; | ||
| import { createServerFn } from '@tanstack/react-start'; | ||
|
|
||
| const throwServerError = createServerFn().handler(async () => { | ||
| throw new Error('Sentry Server Function Test Error'); | ||
| }); | ||
|
|
||
| export const Route = createFileRoute('/')({ | ||
| component: Home, | ||
| }); | ||
|
|
||
| function Home() { | ||
| return ( | ||
| <div> | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| throw new Error('Sentry Client Test Error'); | ||
| }} | ||
| > | ||
| Break the client | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={async () => { | ||
| await throwServerError(); | ||
| }} | ||
| > | ||
| Break server function | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={async () => { | ||
| await fetch('/api/error'); | ||
| }} | ||
| > | ||
| Break API route | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/tanstackstart-react/start-event-proxy.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
|
||
| startEventProxyServer({ | ||
| port: 3031, | ||
| proxyServerName: 'tanstackstart-react', | ||
| }); |
92 changes: 92 additions & 0 deletions
92
dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| 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: { | ||
| handled: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| expect(errorEvent.transaction).toBe('/'); | ||
| }); | ||
|
|
||
| test('Sends API route error to Sentry if manually instrumented', 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: { | ||
| handled: true, | ||
nicohrubec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| expect(errorEvent.transaction).toBe('GET /api/error'); | ||
| }); | ||
26 changes: 26 additions & 0 deletions
26
dev-packages/e2e-tests/test-applications/tanstackstart-react/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2022", | ||
| "useDefineForClassFields": true, | ||
| "lib": ["ES2022", "DOM", "DOM.Iterable"], | ||
| "module": "ESNext", | ||
| "skipLibCheck": true, | ||
|
|
||
| /* Bundler mode */ | ||
| "moduleResolution": "bundler", | ||
| "allowImportingTsExtensions": true, | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
|
|
||
| /* Linting */ | ||
| "strict": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "noFallthroughCasesInSwitch": true, | ||
| "strictNullChecks": true | ||
| }, | ||
| "include": ["src"], | ||
| "references": [{ "path": "./tsconfig.node.json" }] | ||
| } |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/tanstackstart-react/tsconfig.node.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "composite": true, | ||
| "skipLibCheck": true, | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "allowSyntheticDefaultImports": true, | ||
| "strict": true | ||
| }, | ||
| "include": ["vite.config.ts"] | ||
| } |
18 changes: 18 additions & 0 deletions
18
dev-packages/e2e-tests/test-applications/tanstackstart-react/vite.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { defineConfig } from 'vite'; | ||
| import tsConfigPaths from 'vite-tsconfig-paths'; | ||
| import { tanstackStart } from '@tanstack/react-start/plugin/vite'; | ||
| import viteReact from '@vitejs/plugin-react-swc'; | ||
| import { nitro } from 'nitro/vite'; | ||
|
|
||
| export default defineConfig({ | ||
| server: { | ||
| port: 3000, | ||
| }, | ||
| plugins: [ | ||
| tsConfigPaths(), | ||
| tanstackStart(), | ||
| nitro(), | ||
| // react's vite plugin must come after start's vite plugin | ||
| viteReact(), | ||
| ], | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.