|
1 | 1 | import { expect, test } from '@playwright/test'; |
| 2 | +import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'; |
2 | 3 | import axios, { AxiosError, AxiosResponse } from 'axios'; |
3 | | -import { waitForError } from '../event-proxy-server'; |
| 4 | +import { waitForError, waitForTransaction } from '../event-proxy-server'; |
| 5 | +import type { AppRouter } from '../src/app'; |
4 | 6 |
|
5 | 7 | const authToken = process.env.E2E_TEST_AUTH_TOKEN; |
6 | 8 | const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG; |
@@ -130,3 +132,96 @@ test('Should record uncaught exceptions with local variable', async ({ baseURL } |
130 | 132 |
|
131 | 133 | expect(frames[frames.length - 1].vars?.randomVariableToRecord).toBeDefined(); |
132 | 134 | }); |
| 135 | + |
| 136 | +test('Should record transaction for trpc query', async ({ baseURL }) => { |
| 137 | + const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => { |
| 138 | + return transactionEvent.transaction === 'trpc/getSomething'; |
| 139 | + }); |
| 140 | + |
| 141 | + const trpcClient = createTRPCProxyClient<AppRouter>({ |
| 142 | + links: [ |
| 143 | + httpBatchLink({ |
| 144 | + url: `${baseURL}/trpc`, |
| 145 | + }), |
| 146 | + ], |
| 147 | + }); |
| 148 | + |
| 149 | + await trpcClient.getSomething.query('foobar'); |
| 150 | + |
| 151 | + await expect(transactionEventPromise).resolves.toBeDefined(); |
| 152 | + const transaction = await transactionEventPromise; |
| 153 | + |
| 154 | + expect(transaction.contexts?.trpc).toMatchObject({ |
| 155 | + procedure_type: 'query', |
| 156 | + input: 'foobar', |
| 157 | + }); |
| 158 | +}); |
| 159 | + |
| 160 | +test('Should record transaction for trpc mutation', async ({ baseURL }) => { |
| 161 | + const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => { |
| 162 | + return transactionEvent.transaction === 'trpc/createSomething'; |
| 163 | + }); |
| 164 | + |
| 165 | + const trpcClient = createTRPCProxyClient<AppRouter>({ |
| 166 | + links: [ |
| 167 | + httpBatchLink({ |
| 168 | + url: `${baseURL}/trpc`, |
| 169 | + }), |
| 170 | + ], |
| 171 | + }); |
| 172 | + |
| 173 | + await trpcClient.createSomething.mutate(); |
| 174 | + |
| 175 | + await expect(transactionEventPromise).resolves.toBeDefined(); |
| 176 | + const transaction = await transactionEventPromise; |
| 177 | + |
| 178 | + expect(transaction.contexts?.trpc).toMatchObject({ |
| 179 | + procedure_type: 'mutation', |
| 180 | + }); |
| 181 | +}); |
| 182 | + |
| 183 | +test('Should record transaction and error for a crashing trpc handler', async ({ baseURL }) => { |
| 184 | + const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => { |
| 185 | + return transactionEvent.transaction === 'trpc/crashSomething'; |
| 186 | + }); |
| 187 | + |
| 188 | + const errorEventPromise = waitForError('node-express-app', errorEvent => { |
| 189 | + return !!errorEvent?.exception?.values?.some(exception => exception.value?.includes('I crashed in a trpc handler')); |
| 190 | + }); |
| 191 | + |
| 192 | + const trpcClient = createTRPCProxyClient<AppRouter>({ |
| 193 | + links: [ |
| 194 | + httpBatchLink({ |
| 195 | + url: `${baseURL}/trpc`, |
| 196 | + }), |
| 197 | + ], |
| 198 | + }); |
| 199 | + |
| 200 | + await expect(trpcClient.crashSomething.mutate()).rejects.toBeDefined(); |
| 201 | + |
| 202 | + await expect(transactionEventPromise).resolves.toBeDefined(); |
| 203 | + await expect(errorEventPromise).resolves.toBeDefined(); |
| 204 | +}); |
| 205 | + |
| 206 | +test('Should record transaction and error for a trpc handler that returns a status code', async ({ baseURL }) => { |
| 207 | + const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => { |
| 208 | + return transactionEvent.transaction === 'trpc/dontFindSomething'; |
| 209 | + }); |
| 210 | + |
| 211 | + const errorEventPromise = waitForError('node-express-app', errorEvent => { |
| 212 | + return !!errorEvent?.exception?.values?.some(exception => exception.value?.includes('Page not found')); |
| 213 | + }); |
| 214 | + |
| 215 | + const trpcClient = createTRPCProxyClient<AppRouter>({ |
| 216 | + links: [ |
| 217 | + httpBatchLink({ |
| 218 | + url: `${baseURL}/trpc`, |
| 219 | + }), |
| 220 | + ], |
| 221 | + }); |
| 222 | + |
| 223 | + await expect(trpcClient.dontFindSomething.mutate()).rejects.toBeDefined(); |
| 224 | + |
| 225 | + await expect(transactionEventPromise).resolves.toBeDefined(); |
| 226 | + await expect(errorEventPromise).resolves.toBeDefined(); |
| 227 | +}); |
0 commit comments