|
1 |
| -import type { EventProcessor } from '@sentry/core'; |
2 |
| -import type { NodeClient } from '@sentry/node'; |
| 1 | +import type { Event, EventProcessor } from '@sentry/core'; |
3 | 2 | import * as SentryNode from '@sentry/node';
|
4 | 3 | import { getGlobalScope, Scope, SDK_VERSION } from '@sentry/node';
|
5 | 4 | import { beforeEach, describe, expect, it, vi } from 'vitest';
|
6 | 5 | import { init } from '../../src/server';
|
7 |
| -import { clientSourceMapErrorFilter } from '../../src/server/sdk'; |
| 6 | +import { clientSourceMapErrorFilter, lowQualityTransactionsFilter } from '../../src/server/sdk'; |
8 | 7 |
|
9 | 8 | const nodeInit = vi.spyOn(SentryNode, 'init');
|
10 | 9 |
|
@@ -42,41 +41,43 @@ describe('Nuxt Server SDK', () => {
|
42 | 41 | expect(init({})).not.toBeUndefined();
|
43 | 42 | });
|
44 | 43 |
|
45 |
| - describe('lowQualityTransactionsFilter (%s)', () => { |
46 |
| - const beforeSendEvent = vi.fn(event => event); |
47 |
| - const client = init({ |
48 |
| - dsn: 'https://[email protected]/1337', |
49 |
| - }) as NodeClient; |
50 |
| - client.on('beforeSendEvent', beforeSendEvent); |
| 44 | + describe('lowQualityTransactionsFilter', () => { |
| 45 | + const options = { debug: false }; |
| 46 | + const filter = lowQualityTransactionsFilter(options); |
51 | 47 |
|
52 |
| - it.each([ |
53 |
| - [ |
| 48 | + describe('filters out low quality transactions', () => { |
| 49 | + it.each([ |
54 | 50 | 'GET /_nuxt/some_asset.js',
|
55 | 51 | 'GET _nuxt/some_asset.js',
|
56 | 52 | 'GET /icons/favicon.ico',
|
57 | 53 | 'GET /assets/logo.png',
|
58 | 54 | 'GET /icons/zones/forest.svg',
|
59 |
| - ], |
60 |
| - ])('filters out low quality transactions', async transaction => { |
61 |
| - client.captureEvent({ type: 'transaction', transaction }); |
62 |
| - await client!.flush(); |
63 |
| - expect(beforeSendEvent).not.toHaveBeenCalled(); |
| 55 | + ])('filters out low quality transaction: (%s)', transaction => { |
| 56 | + const event = { type: 'transaction' as const, transaction }; |
| 57 | + expect(filter(event, {})).toBeNull(); |
| 58 | + }); |
64 | 59 | });
|
65 | 60 |
|
66 |
| - // Nuxt parametrizes routes sometimes in a special way - especially catchAll o.O |
67 |
| - it.each(['GET /', 'POST /_server', 'GET /catchAll/:id(.*)*', 'GET /article/:slug()', 'GET /user/:id'])( |
68 |
| - 'does not filter out high quality or route transactions (%s)', |
69 |
| - async transaction => { |
70 |
| - client.captureEvent({ type: 'transaction', transaction }); |
71 |
| - await client!.flush(); |
72 |
| - expect(beforeSendEvent).toHaveBeenCalledWith( |
73 |
| - expect.objectContaining({ |
74 |
| - transaction, |
75 |
| - }), |
76 |
| - expect.any(Object), |
77 |
| - ); |
78 |
| - }, |
79 |
| - ); |
| 61 | + describe('keeps high quality transactions', () => { |
| 62 | + // Nuxt parametrizes routes sometimes in a special way - especially catchAll o.O |
| 63 | + it.each(['GET /', 'POST /_server', 'GET /catchAll/:id(.*)*', 'GET /article/:slug()', 'GET /user/:id'])( |
| 64 | + 'does not filter out route transactions (%s)', |
| 65 | + transaction => { |
| 66 | + const event = { type: 'transaction' as const, transaction }; |
| 67 | + expect(filter(event, {})).toEqual(event); |
| 68 | + }, |
| 69 | + ); |
| 70 | + }); |
| 71 | + |
| 72 | + it('does not filter non-transaction events', () => { |
| 73 | + const event = { type: 'error' as const, transaction: 'GET /assets/image.png' } as unknown as Event; |
| 74 | + expect(filter(event, {})).toEqual(event); |
| 75 | + }); |
| 76 | + |
| 77 | + it('handles events without transaction property', () => { |
| 78 | + const event = { type: 'transaction' as const }; |
| 79 | + expect(filter(event, {})).toEqual(event); |
| 80 | + }); |
80 | 81 | });
|
81 | 82 |
|
82 | 83 | it('registers an event processor', async () => {
|
|
0 commit comments