-
-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathfeatureMarkers.test.ts
More file actions
55 lines (39 loc) · 2 KB
/
Copy pathfeatureMarkers.test.ts
File metadata and controls
55 lines (39 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { captureException, getClient, setCurrentClient } from '@sentry/core';
import { registerFeatureMarker } from '../../src/js/utils/featureMarkers';
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
describe('registerFeatureMarker', () => {
beforeEach(() => {
setCurrentClient(new TestClient(getDefaultTestClientOptions()));
getClient()?.init();
});
test('registers a no-op named integration on the current client', () => {
expect(getClient()?.getIntegrationByName('SomeFeature')).toBeUndefined();
registerFeatureMarker('SomeFeature');
expect(getClient()?.getIntegrationByName('SomeFeature')).toEqual({ name: 'SomeFeature' });
});
test('is idempotent — second call with the same name does not overwrite', () => {
const first = { name: 'IdempotentFeature', setupOnce: jest.fn() };
getClient()?.addIntegration(first);
registerFeatureMarker('IdempotentFeature');
expect(getClient()?.getIntegrationByName('IdempotentFeature')).toBe(first);
});
test('is a no-op when no client is available', () => {
setCurrentClient(undefined as unknown as TestClient);
expect(() => registerFeatureMarker('NoClientFeature')).not.toThrow();
});
test('accepts an explicit client argument', () => {
const explicitClient = new TestClient(getDefaultTestClientOptions());
explicitClient.init();
registerFeatureMarker('ExplicitClientFeature', explicitClient);
expect(explicitClient.getIntegrationByName('ExplicitClientFeature')).toEqual({ name: 'ExplicitClientFeature' });
expect(getClient()?.getIntegrationByName('ExplicitClientFeature')).toBeUndefined();
});
test('the marker name is attached to `event.sdk.integrations` on captured events', async () => {
registerFeatureMarker('AdoptionSignal');
captureException(new Error('boom'));
await getClient()?.flush();
const client = getClient() as TestClient;
const event = client.eventQueue[0];
expect(event?.sdk?.integrations).toContain('AdoptionSignal');
});
});