Skip to content

Commit 420aaf8

Browse files
authored
test(nuxt): Unit tests for event filter (#13229)
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
1 parent c71177b commit 420aaf8

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

packages/nuxt/test/client/runtime/utils.test.ts renamed to packages/nuxt/test/runtime/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { extractErrorContext } from '../../../src/runtime/utils';
2+
import { extractErrorContext } from '../../src/runtime/utils';
33

44
describe('extractErrorContext', () => {
55
it('returns empty object for undefined or empty context', () => {

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as SentryNode from '@sentry/node';
2+
import type { NodeClient } from '@sentry/node';
23
import { SDK_VERSION } from '@sentry/node';
34
import { beforeEach, describe, expect, it, vi } from 'vitest';
45
import { init } from '../../src/server';
@@ -38,5 +39,47 @@ describe('Nuxt Server SDK', () => {
3839
it('returns client from init', () => {
3940
expect(init({})).not.toBeUndefined();
4041
});
42+
43+
it('filters out low quality transactions', async () => {
44+
const beforeSendEvent = vi.fn(event => event);
45+
const client = init({
46+
dsn: 'https://[email protected]/1337',
47+
}) as NodeClient;
48+
client.on('beforeSendEvent', beforeSendEvent);
49+
50+
client.captureEvent({ type: 'transaction', transaction: 'GET /' });
51+
client.captureEvent({ type: 'transaction', transaction: 'GET /_nuxt/some_asset.js' });
52+
// Although this has the name of the build asset directory (_nuxt), it should not be filtered out as it would not match the regex
53+
client.captureEvent({ type: 'transaction', transaction: 'GET _nuxt/some_asset.js' });
54+
client.captureEvent({ type: 'transaction', transaction: 'POST /_server' });
55+
56+
await client!.flush();
57+
58+
expect(beforeSendEvent).toHaveBeenCalledTimes(3);
59+
expect(beforeSendEvent).toHaveBeenCalledWith(
60+
expect.objectContaining({
61+
transaction: 'GET /',
62+
}),
63+
expect.any(Object),
64+
);
65+
expect(beforeSendEvent).toHaveBeenCalledWith(
66+
expect.objectContaining({
67+
transaction: 'GET _nuxt/some_asset.js',
68+
}),
69+
expect.any(Object),
70+
);
71+
expect(beforeSendEvent).not.toHaveBeenCalledWith(
72+
expect.objectContaining({
73+
transaction: 'GET /_nuxt/some_asset.js',
74+
}),
75+
expect.any(Object),
76+
);
77+
expect(beforeSendEvent).toHaveBeenCalledWith(
78+
expect.objectContaining({
79+
transaction: 'POST /_server',
80+
}),
81+
expect.any(Object),
82+
);
83+
});
4184
});
4285
});

0 commit comments

Comments
 (0)