-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsdk.test.ts
81 lines (65 loc) · 2.58 KB
/
sdk.test.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { BrowserClient } from '@sentry/svelte';
import * as SentrySvelte from '@sentry/svelte';
import { SDK_VERSION, getClient, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/svelte';
import { init } from '../../src/client';
const svelteInit = vi.spyOn(SentrySvelte, 'init');
describe('Sentry client SDK', () => {
describe('init', () => {
afterEach(() => {
vi.clearAllMocks();
getGlobalScope().clear();
getIsolationScope().clear();
getCurrentScope().clear();
getCurrentScope().setClient(undefined);
});
it('adds SvelteKit metadata to the SDK options', () => {
expect(svelteInit).not.toHaveBeenCalled();
init({});
expect(svelteInit).toHaveBeenCalledTimes(1);
expect(svelteInit).toHaveBeenCalledWith(
expect.objectContaining({
_metadata: {
sdk: {
name: 'sentry.javascript.sveltekit',
version: SDK_VERSION,
packages: [
{ name: 'npm:@sentry/sveltekit', version: SDK_VERSION },
{ name: 'npm:@sentry/svelte', version: SDK_VERSION },
],
},
},
}),
);
});
describe('automatically added integrations', () => {
it.each([
['tracesSampleRate', { tracesSampleRate: 0 }],
['tracesSampler', { tracesSampler: () => 1.0 }],
['no tracing option set', {}],
])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => {
init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
...tracingOptions,
});
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
expect(browserTracing).toBeDefined();
});
it("doesn't add a browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => {
// This is the closest we can get to unit-testing the `__SENTRY_TRACING__` tree-shaking guard
// IRL, the code to add the integration would most likely be removed by the bundler.
globalThis.__SENTRY_TRACING__ = false;
init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
tracesSampleRate: 1,
});
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
expect(browserTracing).toBeUndefined();
delete globalThis.__SENTRY_TRACING__;
});
});
it('returns client from init', () => {
expect(init({})).not.toBeUndefined();
});
});
});