Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Apr 24, 2024
1 parent c62591f commit 3d3fdd1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 13 deletions.
54 changes: 47 additions & 7 deletions packages/nextjs/test/clientSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import type { Integration } from '@sentry/types';
import { logger } from '@sentry/utils';
import { JSDOM } from 'jsdom';

import { BrowserTracing, breadcrumbsIntegration, init, nextRouterInstrumentation } from '../src/client';
import {
BrowserTracing,
breadcrumbsIntegration,
browserTracingIntegration as nextjsBrowserTracingIntegration,
init,
nextRouterInstrumentation,
} from '../src/client';

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

// This shows that the user-configured options are still here
expect(integration?.options?.finalTimeout).toEqual(10);
expect(integration?.options.instrumentNavigation).toBe(false);
expect(integration?.options.instrumentPageLoad).toBe(true);

// the hooks is correctly invoked
expect(beforeStartSpan).toHaveBeenCalledTimes(1);
expect(beforeStartSpan).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -187,11 +189,49 @@ describe('Client init()', () => {
}),
);

// it is the svelte kit variety
// it correctly starts the page load span
expect(getActiveSpan()).toBeDefined();
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
'auto.pageload.nextjs.app_router_instrumentation',
);

// This shows that the user-configured options are still here
expect(integration?.options.finalTimeout).toEqual(10);
expect(integration?.options.instrumentNavigation).toBe(false);
expect(integration?.options.instrumentPageLoad).toBe(true);
});

it('forces correct router instrumentation if user provides Next.js `browserTracingIntegration` ', () => {
init({
dsn: TEST_DSN,
integrations: [
nextjsBrowserTracingIntegration({
finalTimeout: 10,
instrumentNavigation: false,
}),
],
enableTracing: true,
});

const client = getClient<BrowserClient>()!;
// eslint-disable-next-line deprecation/deprecation
const integration = client.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>('BrowserTracing');

expect(integration).toBeDefined();

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

// it correctly starts the pageload span
expect(getActiveSpan()).toBeDefined();
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
'auto.pageload.nextjs.app_router_instrumentation',
);

// This shows that the user-configured options are still here
expect(integration?.options.finalTimeout).toEqual(10);
expect(integration?.options.instrumentNavigation).toBe(false);
expect(integration?.options.instrumentPageLoad).toBe(true);
});

it('forces correct router instrumentation if user provides `BrowserTracing` in a function', () => {
Expand Down
43 changes: 37 additions & 6 deletions packages/sveltekit/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import * as SentrySvelte from '@sentry/svelte';
import { SDK_VERSION, WINDOW, browserTracingIntegration } from '@sentry/svelte';
import { vi } from 'vitest';

import { BrowserTracing, init } from '../../src/client';
import {
BrowserTracing,
browserTracingIntegration as sveltekitBrowserTracingIntegration,
init,
} from '../../src/client';
import { svelteKitRoutingInstrumentation } from '../../src/client/router';

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

expect(browserTracing).toBeDefined();

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

// it is the svelte kit variety
expect(getActiveSpan()).toBeDefined();
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
'auto.pageload.sveltekit',
);

// This shows that the user-configured options are still here
expect(options?.finalTimeout).toEqual(10);
expect(options?.instrumentPageLoad).toEqual(true);
expect(options?.instrumentNavigation).toEqual(false);
expect(browserTracing?.options.finalTimeout).toEqual(10);
expect(browserTracing?.options.instrumentPageLoad).toEqual(true);
expect(browserTracing?.options.instrumentNavigation).toEqual(false);
});

// it is the svelte kit variety
it('forces correct router instrumentation if user provides Sveltekit `browserTracingIntegration` ', () => {
init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [sveltekitBrowserTracingIntegration({ finalTimeout: 10, instrumentNavigation: false })],
enableTracing: true,
});

const client = getClient<BrowserClient>()!;
// eslint-disable-next-line deprecation/deprecation
const integration = client.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>('BrowserTracing');

expect(integration).toBeDefined();

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

// it correctly starts the pageload span
expect(getActiveSpan()).toBeDefined();
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
'auto.pageload.sveltekit',
);

// This shows that the user-configured options are still here
expect(integration?.options.finalTimeout).toEqual(10);
expect(integration?.options.instrumentNavigation).toBe(false);
expect(integration?.options.instrumentPageLoad).toBe(true);
});
});
});
Expand Down

0 comments on commit 3d3fdd1

Please sign in to comment.