-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...es/nuxt/test/client/runtime/utils.test.ts → packages/nuxt/test/runtime/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
@@ -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://[email protected]/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), | ||
); | ||
}); | ||
}); | ||
}); |