|
1 | 1 | import * as SentryNode from '@sentry/node';
|
| 2 | +import type { NodeClient } from '@sentry/node'; |
2 | 3 | import { SDK_VERSION } from '@sentry/node';
|
3 | 4 | import { beforeEach, describe, expect, it, vi } from 'vitest';
|
4 | 5 | import { init } from '../../src/server';
|
@@ -38,5 +39,47 @@ describe('Nuxt Server SDK', () => {
|
38 | 39 | it('returns client from init', () => {
|
39 | 40 | expect(init({})).not.toBeUndefined();
|
40 | 41 | });
|
| 42 | + |
| 43 | + it('filters out low quality transactions', async () => { |
| 44 | + const beforeSendEvent = vi.fn(event => event); |
| 45 | + const client = init({ |
| 46 | + dsn: 'https://[email protected]/1337', |
| 47 | + }) as NodeClient; |
| 48 | + client.on('beforeSendEvent', beforeSendEvent); |
| 49 | + |
| 50 | + client.captureEvent({ type: 'transaction', transaction: 'GET /' }); |
| 51 | + client.captureEvent({ type: 'transaction', transaction: 'GET /_nuxt/some_asset.js' }); |
| 52 | + // Although this has the name of the build asset directory (_nuxt), it should not be filtered out as it would not match the regex |
| 53 | + client.captureEvent({ type: 'transaction', transaction: 'GET _nuxt/some_asset.js' }); |
| 54 | + client.captureEvent({ type: 'transaction', transaction: 'POST /_server' }); |
| 55 | + |
| 56 | + await client!.flush(); |
| 57 | + |
| 58 | + expect(beforeSendEvent).toHaveBeenCalledTimes(3); |
| 59 | + expect(beforeSendEvent).toHaveBeenCalledWith( |
| 60 | + expect.objectContaining({ |
| 61 | + transaction: 'GET /', |
| 62 | + }), |
| 63 | + expect.any(Object), |
| 64 | + ); |
| 65 | + expect(beforeSendEvent).toHaveBeenCalledWith( |
| 66 | + expect.objectContaining({ |
| 67 | + transaction: 'GET _nuxt/some_asset.js', |
| 68 | + }), |
| 69 | + expect.any(Object), |
| 70 | + ); |
| 71 | + expect(beforeSendEvent).not.toHaveBeenCalledWith( |
| 72 | + expect.objectContaining({ |
| 73 | + transaction: 'GET /_nuxt/some_asset.js', |
| 74 | + }), |
| 75 | + expect.any(Object), |
| 76 | + ); |
| 77 | + expect(beforeSendEvent).toHaveBeenCalledWith( |
| 78 | + expect.objectContaining({ |
| 79 | + transaction: 'POST /_server', |
| 80 | + }), |
| 81 | + expect.any(Object), |
| 82 | + ); |
| 83 | + }); |
41 | 84 | });
|
42 | 85 | });
|
0 commit comments