|
1 |
| -import type { NodeClient } from '@sentry/node'; |
2 |
| -import { SDK_VERSION } from '@sentry/node'; |
| 1 | +import type { EventProcessor } from '@sentry/core'; |
| 2 | +import { getGlobalScope, Scope, SDK_VERSION } from '@sentry/node'; |
3 | 3 | import * as SentryNode from '@sentry/node';
|
4 | 4 | import { beforeEach, describe, expect, it, vi } from 'vitest';
|
5 | 5 | import { init as solidStartInit } from '../../src/server';
|
| 6 | +import { lowQualityTransactionsFilter } from '../../src/server/utils'; |
6 | 7 |
|
7 | 8 | const browserInit = vi.spyOn(SentryNode, 'init');
|
8 | 9 |
|
@@ -34,37 +35,52 @@ describe('Initialize Solid Start SDK', () => {
|
34 | 35 | expect(browserInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
|
35 | 36 | });
|
36 | 37 |
|
37 |
| - it('filters out low quality transactions', async () => { |
38 |
| - const beforeSendEvent = vi.fn(event => event); |
39 |
| - const client = solidStartInit({ |
40 |
| - dsn: 'https://[email protected]/1337', |
41 |
| - }) as NodeClient; |
42 |
| - client.on('beforeSendEvent', beforeSendEvent); |
| 38 | + describe('lowQualityTransactionsFilter', () => { |
| 39 | + const options = { debug: false }; |
| 40 | + const filter = lowQualityTransactionsFilter(options); |
| 41 | + |
| 42 | + describe('filters out low quality transactions', () => { |
| 43 | + it.each(['GET /_build/some_asset.js', 'GET /_build/app.js', 'GET /_build/assets/logo.png'])( |
| 44 | + 'filters out low quality transaction: (%s)', |
| 45 | + transaction => { |
| 46 | + const event = { type: 'transaction' as const, transaction }; |
| 47 | + expect(filter(event, {})).toBeNull(); |
| 48 | + }, |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + describe('keeps high quality transactions', () => { |
| 53 | + it.each(['GET /', 'POST /_server'])('does not filter out route transactions (%s)', transaction => { |
| 54 | + const event = { type: 'transaction' as const, transaction }; |
| 55 | + expect(filter(event, {})).toEqual(event); |
| 56 | + }); |
| 57 | + }); |
43 | 58 |
|
44 |
| - client.captureEvent({ type: 'transaction', transaction: 'GET /' }); |
45 |
| - client.captureEvent({ type: 'transaction', transaction: 'GET /_build/some_asset.js' }); |
46 |
| - client.captureEvent({ type: 'transaction', transaction: 'POST /_server' }); |
| 59 | + it('does not filter non-transaction events', () => { |
| 60 | + const event = { type: 'error' as const, transaction: 'GET /_build/app.js' } as any; |
| 61 | + expect(filter(event, {})).toEqual(event); |
| 62 | + }); |
| 63 | + |
| 64 | + it('handles events without transaction property', () => { |
| 65 | + const event = { type: 'transaction' as const }; |
| 66 | + expect(filter(event, {})).toEqual(event); |
| 67 | + }); |
| 68 | + }); |
47 | 69 |
|
48 |
| - await client!.flush(); |
| 70 | + it('registers an event processor', () => { |
| 71 | + let passedEventProcessors: EventProcessor[] = []; |
| 72 | + const addEventProcessor = vi |
| 73 | + .spyOn(getGlobalScope(), 'addEventProcessor') |
| 74 | + .mockImplementation((eventProcessor: EventProcessor) => { |
| 75 | + passedEventProcessors = [...passedEventProcessors, eventProcessor]; |
| 76 | + return new Scope(); |
| 77 | + }); |
| 78 | + |
| 79 | + solidStartInit({ |
| 80 | + dsn: 'https://[email protected]/1337', |
| 81 | + }); |
49 | 82 |
|
50 |
| - expect(beforeSendEvent).toHaveBeenCalledTimes(2); |
51 |
| - expect(beforeSendEvent).toHaveBeenCalledWith( |
52 |
| - expect.objectContaining({ |
53 |
| - transaction: 'GET /', |
54 |
| - }), |
55 |
| - expect.any(Object), |
56 |
| - ); |
57 |
| - expect(beforeSendEvent).not.toHaveBeenCalledWith( |
58 |
| - expect.objectContaining({ |
59 |
| - transaction: 'GET /_build/some_asset.js', |
60 |
| - }), |
61 |
| - expect.any(Object), |
62 |
| - ); |
63 |
| - expect(beforeSendEvent).toHaveBeenCalledWith( |
64 |
| - expect.objectContaining({ |
65 |
| - transaction: 'POST /_server', |
66 |
| - }), |
67 |
| - expect.any(Object), |
68 |
| - ); |
| 83 | + expect(addEventProcessor).toHaveBeenCalledTimes(1); |
| 84 | + expect(passedEventProcessors[0]?.id).toEqual('SolidStartLowQualityTransactionsFilter'); |
69 | 85 | });
|
70 | 86 | });
|
0 commit comments