Skip to content

Commit

Permalink
test(nuxt): Unit tests for event filter (#13229)
Browse files Browse the repository at this point in the history
Adding more convenient unit test. There is already an E2E test for this:
https://github.com/getsentry/sentry-javascript/blob/b6cf7b0cabc27a84e962f0a1e408465cc87fd961/dev-packages/e2e-tests/test-applications/nuxt-3/tests/performance.server.test.ts#L24

Also moved two files in the `test` folder to resemble the `src` folder
  • Loading branch information
s1gr1d committed Aug 5, 2024
1 parent c71177b commit 420aaf8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { extractErrorContext } from '../../../src/runtime/utils';
import { extractErrorContext } from '../../src/runtime/utils';

describe('extractErrorContext', () => {
it('returns empty object for undefined or empty context', () => {
Expand Down
43 changes: 43 additions & 0 deletions packages/nuxt/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as SentryNode from '@sentry/node';
import type { NodeClient } from '@sentry/node';
import { SDK_VERSION } from '@sentry/node';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { init } from '../../src/server';
Expand Down Expand Up @@ -38,5 +39,47 @@ describe('Nuxt Server SDK', () => {
it('returns client from init', () => {
expect(init({})).not.toBeUndefined();
});

it('filters out low quality transactions', async () => {
const beforeSendEvent = vi.fn(event => event);
const client = init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
}) as NodeClient;
client.on('beforeSendEvent', beforeSendEvent);

client.captureEvent({ type: 'transaction', transaction: 'GET /' });
client.captureEvent({ type: 'transaction', transaction: 'GET /_nuxt/some_asset.js' });
// Although this has the name of the build asset directory (_nuxt), it should not be filtered out as it would not match the regex
client.captureEvent({ type: 'transaction', transaction: 'GET _nuxt/some_asset.js' });
client.captureEvent({ type: 'transaction', transaction: 'POST /_server' });

await client!.flush();

expect(beforeSendEvent).toHaveBeenCalledTimes(3);
expect(beforeSendEvent).toHaveBeenCalledWith(
expect.objectContaining({
transaction: 'GET /',
}),
expect.any(Object),
);
expect(beforeSendEvent).toHaveBeenCalledWith(
expect.objectContaining({
transaction: 'GET _nuxt/some_asset.js',
}),
expect.any(Object),
);
expect(beforeSendEvent).not.toHaveBeenCalledWith(
expect.objectContaining({
transaction: 'GET /_nuxt/some_asset.js',
}),
expect.any(Object),
);
expect(beforeSendEvent).toHaveBeenCalledWith(
expect.objectContaining({
transaction: 'POST /_server',
}),
expect.any(Object),
);
});
});
});

0 comments on commit 420aaf8

Please sign in to comment.