Skip to content

Commit 3d3fdd1

Browse files
committed
more tests
1 parent c62591f commit 3d3fdd1

File tree

2 files changed

+84
-13
lines changed

2 files changed

+84
-13
lines changed

packages/nextjs/test/clientSdk.test.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import type { Integration } from '@sentry/types';
1313
import { logger } from '@sentry/utils';
1414
import { JSDOM } from 'jsdom';
1515

16-
import { BrowserTracing, breadcrumbsIntegration, init, nextRouterInstrumentation } from '../src/client';
16+
import {
17+
BrowserTracing,
18+
breadcrumbsIntegration,
19+
browserTracingIntegration as nextjsBrowserTracingIntegration,
20+
init,
21+
nextRouterInstrumentation,
22+
} from '../src/client';
1723

1824
const reactInit = jest.spyOn(SentryReact, 'init');
1925
const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent');
@@ -174,11 +180,7 @@ describe('Client init()', () => {
174180
// It is a "new" browser tracing integration
175181
expect(typeof integration?.afterAllSetup).toBe('function');
176182

177-
// This shows that the user-configured options are still here
178-
expect(integration?.options?.finalTimeout).toEqual(10);
179-
expect(integration?.options.instrumentNavigation).toBe(false);
180-
expect(integration?.options.instrumentPageLoad).toBe(true);
181-
183+
// the hooks is correctly invoked
182184
expect(beforeStartSpan).toHaveBeenCalledTimes(1);
183185
expect(beforeStartSpan).toHaveBeenCalledWith(
184186
expect.objectContaining({
@@ -187,11 +189,49 @@ describe('Client init()', () => {
187189
}),
188190
);
189191

190-
// it is the svelte kit variety
192+
// it correctly starts the page load span
193+
expect(getActiveSpan()).toBeDefined();
194+
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
195+
'auto.pageload.nextjs.app_router_instrumentation',
196+
);
197+
198+
// This shows that the user-configured options are still here
199+
expect(integration?.options.finalTimeout).toEqual(10);
200+
expect(integration?.options.instrumentNavigation).toBe(false);
201+
expect(integration?.options.instrumentPageLoad).toBe(true);
202+
});
203+
204+
it('forces correct router instrumentation if user provides Next.js `browserTracingIntegration` ', () => {
205+
init({
206+
dsn: TEST_DSN,
207+
integrations: [
208+
nextjsBrowserTracingIntegration({
209+
finalTimeout: 10,
210+
instrumentNavigation: false,
211+
}),
212+
],
213+
enableTracing: true,
214+
});
215+
216+
const client = getClient<BrowserClient>()!;
217+
// eslint-disable-next-line deprecation/deprecation
218+
const integration = client.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>('BrowserTracing');
219+
220+
expect(integration).toBeDefined();
221+
222+
// It is a "new" browser tracing integration
223+
expect(typeof integration?.afterAllSetup).toBe('function');
224+
225+
// it correctly starts the pageload span
191226
expect(getActiveSpan()).toBeDefined();
192227
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
193228
'auto.pageload.nextjs.app_router_instrumentation',
194229
);
230+
231+
// This shows that the user-configured options are still here
232+
expect(integration?.options.finalTimeout).toEqual(10);
233+
expect(integration?.options.instrumentNavigation).toBe(false);
234+
expect(integration?.options.instrumentPageLoad).toBe(true);
195235
});
196236

197237
it('forces correct router instrumentation if user provides `BrowserTracing` in a function', () => {

packages/sveltekit/test/client/sdk.test.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import * as SentrySvelte from '@sentry/svelte';
1111
import { SDK_VERSION, WINDOW, browserTracingIntegration } from '@sentry/svelte';
1212
import { vi } from 'vitest';
1313

14-
import { BrowserTracing, init } from '../../src/client';
14+
import {
15+
BrowserTracing,
16+
browserTracingIntegration as sveltekitBrowserTracingIntegration,
17+
init,
18+
} from '../../src/client';
1519
import { svelteKitRoutingInstrumentation } from '../../src/client/router';
1620

1721
const svelteInit = vi.spyOn(SentrySvelte, 'init');
@@ -145,23 +149,50 @@ describe('Sentry client SDK', () => {
145149
getClient<BrowserClient>()?.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>(
146150
'BrowserTracing',
147151
);
148-
const options = browserTracing?.options;
149152

150153
expect(browserTracing).toBeDefined();
151154

152155
// It is a "new" browser tracing integration
153156
expect(typeof browserTracing?.afterAllSetup).toBe('function');
154157

158+
// it is the svelte kit variety
159+
expect(getActiveSpan()).toBeDefined();
160+
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
161+
'auto.pageload.sveltekit',
162+
);
163+
155164
// This shows that the user-configured options are still here
156-
expect(options?.finalTimeout).toEqual(10);
157-
expect(options?.instrumentPageLoad).toEqual(true);
158-
expect(options?.instrumentNavigation).toEqual(false);
165+
expect(browserTracing?.options.finalTimeout).toEqual(10);
166+
expect(browserTracing?.options.instrumentPageLoad).toEqual(true);
167+
expect(browserTracing?.options.instrumentNavigation).toEqual(false);
168+
});
159169

160-
// it is the svelte kit variety
170+
it('forces correct router instrumentation if user provides Sveltekit `browserTracingIntegration` ', () => {
171+
init({
172+
dsn: 'https://[email protected]/1337',
173+
integrations: [sveltekitBrowserTracingIntegration({ finalTimeout: 10, instrumentNavigation: false })],
174+
enableTracing: true,
175+
});
176+
177+
const client = getClient<BrowserClient>()!;
178+
// eslint-disable-next-line deprecation/deprecation
179+
const integration = client.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>('BrowserTracing');
180+
181+
expect(integration).toBeDefined();
182+
183+
// It is a "new" browser tracing integration
184+
expect(typeof integration?.afterAllSetup).toBe('function');
185+
186+
// it correctly starts the pageload span
161187
expect(getActiveSpan()).toBeDefined();
162188
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
163189
'auto.pageload.sveltekit',
164190
);
191+
192+
// This shows that the user-configured options are still here
193+
expect(integration?.options.finalTimeout).toEqual(10);
194+
expect(integration?.options.instrumentNavigation).toBe(false);
195+
expect(integration?.options.instrumentPageLoad).toBe(true);
165196
});
166197
});
167198
});

0 commit comments

Comments
 (0)