Skip to content

Commit 115c3e6

Browse files
authored
test(nuxt): Don't rely on flushing for lowQualityTransactionFilter (#17406)
The test relied on `flush` and if the network functionality of CI does not work 100%, this test produces a timeout and fails.
1 parent 05af8d0 commit 115c3e6

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

packages/nuxt/test/server/sdk.test.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { EventProcessor } from '@sentry/core';
2-
import type { NodeClient } from '@sentry/node';
1+
import type { Event, EventProcessor } from '@sentry/core';
32
import * as SentryNode from '@sentry/node';
43
import { getGlobalScope, Scope, SDK_VERSION } from '@sentry/node';
54
import { beforeEach, describe, expect, it, vi } from 'vitest';
65
import { init } from '../../src/server';
7-
import { clientSourceMapErrorFilter } from '../../src/server/sdk';
6+
import { clientSourceMapErrorFilter, lowQualityTransactionsFilter } from '../../src/server/sdk';
87

98
const nodeInit = vi.spyOn(SentryNode, 'init');
109

@@ -42,41 +41,43 @@ describe('Nuxt Server SDK', () => {
4241
expect(init({})).not.toBeUndefined();
4342
});
4443

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);
5147

52-
it.each([
53-
[
48+
describe('filters out low quality transactions', () => {
49+
it.each([
5450
'GET /_nuxt/some_asset.js',
5551
'GET _nuxt/some_asset.js',
5652
'GET /icons/favicon.ico',
5753
'GET /assets/logo.png',
5854
'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+
});
6459
});
6560

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+
});
8081
});
8182

8283
it('registers an event processor', async () => {

0 commit comments

Comments
 (0)