|
| 1 | +import type { Client, ClientOptions } from '@sentry/core'; |
| 2 | +import { shouldIgnoreSpan } from '@sentry/core'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | +import { SPOTLIGHT_IGNORE_SPANS, spotlightBrowserIntegration } from '../../src/integrations/spotlight'; |
| 5 | + |
| 6 | +function makeMockClient(initial: Partial<ClientOptions> = {}): Client { |
| 7 | + const options = { ...initial } as ClientOptions; |
| 8 | + return { getOptions: () => options } as Client; |
| 9 | +} |
| 10 | + |
| 11 | +function setupIntegrationAndGetIgnoreSpans(initial: Partial<ClientOptions> = {}) { |
| 12 | + const integration = spotlightBrowserIntegration(); |
| 13 | + const client = makeMockClient(initial); |
| 14 | + integration.beforeSetup!(client); |
| 15 | + return client.getOptions().ignoreSpans!; |
| 16 | +} |
| 17 | + |
| 18 | +describe('spotlightBrowserIntegration', () => { |
| 19 | + it('appends spotlight interaction filters to ignoreSpans', () => { |
| 20 | + expect(setupIntegrationAndGetIgnoreSpans()).toEqual(SPOTLIGHT_IGNORE_SPANS); |
| 21 | + }); |
| 22 | + |
| 23 | + it('preserves user-provided ignoreSpans entries', () => { |
| 24 | + expect(setupIntegrationAndGetIgnoreSpans({ ignoreSpans: [/keep-me/] })).toEqual([ |
| 25 | + /keep-me/, |
| 26 | + ...SPOTLIGHT_IGNORE_SPANS, |
| 27 | + ]); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('drops spotlight interaction spans', () => { |
| 31 | + it.each([ |
| 32 | + ['click on spotlight overlay', 'body > div#sentry-spotlight > div.overlay'], |
| 33 | + ['click on spotlight button', 'body > div > div#sentry-spotlight > button.close'], |
| 34 | + ['click on nested spotlight element', 'html > body > aside#sentry-spotlight'], |
| 35 | + ])('%s', (_label, name) => { |
| 36 | + const ignoreSpans = setupIntegrationAndGetIgnoreSpans(); |
| 37 | + expect(shouldIgnoreSpan({ description: name, op: 'ui.interaction.click' }, ignoreSpans)).toBe(true); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('keeps non-spotlight interaction spans', () => { |
| 42 | + it.each([ |
| 43 | + ['regular click', 'body > div.main > button.submit', 'ui.interaction.click'], |
| 44 | + ['regular ui action', '/dashboard', 'ui.action.click'], |
| 45 | + ['non-interaction span', 'GET /api/data', 'http.client'], |
| 46 | + ])('%s', (_label, name, op) => { |
| 47 | + const ignoreSpans = setupIntegrationAndGetIgnoreSpans(); |
| 48 | + expect(shouldIgnoreSpan({ description: name, op }, ignoreSpans)).toBe(false); |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments