Skip to content

test(nuxt): Don't rely on flushing for lowQualityTransactionFilter #17406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions packages/nuxt/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { EventProcessor } from '@sentry/core';
import type { NodeClient } from '@sentry/node';
import type { Event, EventProcessor } from '@sentry/core';
import * as SentryNode from '@sentry/node';
import { getGlobalScope, Scope, SDK_VERSION } from '@sentry/node';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { init } from '../../src/server';
import { clientSourceMapErrorFilter } from '../../src/server/sdk';
import { clientSourceMapErrorFilter, lowQualityTransactionsFilter } from '../../src/server/sdk';

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

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

describe('lowQualityTransactionsFilter (%s)', () => {
const beforeSendEvent = vi.fn(event => event);
const client = init({
dsn: 'https://[email protected]/1337',
}) as NodeClient;
client.on('beforeSendEvent', beforeSendEvent);
describe('lowQualityTransactionsFilter', () => {
const options = { debug: false };
const filter = lowQualityTransactionsFilter(options);

it.each([
[
describe('filters out low quality transactions', () => {
it.each([
'GET /_nuxt/some_asset.js',
'GET _nuxt/some_asset.js',
'GET /icons/favicon.ico',
'GET /assets/logo.png',
'GET /icons/zones/forest.svg',
],
])('filters out low quality transactions', async transaction => {
client.captureEvent({ type: 'transaction', transaction });
await client!.flush();
expect(beforeSendEvent).not.toHaveBeenCalled();
])('filters out low quality transaction: (%s)', transaction => {
const event = { type: 'transaction' as const, transaction };
expect(filter(event, {})).toBeNull();
});
});

// Nuxt parametrizes routes sometimes in a special way - especially catchAll o.O
it.each(['GET /', 'POST /_server', 'GET /catchAll/:id(.*)*', 'GET /article/:slug()', 'GET /user/:id'])(
'does not filter out high quality or route transactions (%s)',
async transaction => {
client.captureEvent({ type: 'transaction', transaction });
await client!.flush();
expect(beforeSendEvent).toHaveBeenCalledWith(
expect.objectContaining({
transaction,
}),
expect.any(Object),
);
},
);
describe('keeps high quality transactions', () => {
// Nuxt parametrizes routes sometimes in a special way - especially catchAll o.O
it.each(['GET /', 'POST /_server', 'GET /catchAll/:id(.*)*', 'GET /article/:slug()', 'GET /user/:id'])(
'does not filter out route transactions (%s)',
transaction => {
const event = { type: 'transaction' as const, transaction };
expect(filter(event, {})).toEqual(event);
},
);
});

it('does not filter non-transaction events', () => {
const event = { type: 'error' as const, transaction: 'GET /assets/image.png' } as unknown as Event;
expect(filter(event, {})).toEqual(event);
});

it('handles events without transaction property', () => {
const event = { type: 'transaction' as const };
expect(filter(event, {})).toEqual(event);
});
});

it('registers an event processor', async () => {
Expand Down
Loading