Skip to content

Commit 9bfa4c1

Browse files
committed
test(sveltekit): fix sveltekit unit tests
Need to use imports from @sentry/core, otherwise the scope contexts are not matching.
1 parent 9114bcc commit 9bfa4c1

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

packages/sveltekit/test/server/handle.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {
99
} from '@sentry/core';
1010
import type { EventEnvelopeHeaders, Span } from '@sentry/core';
1111
import { NodeClient, setCurrentClient } from '@sentry/node';
12-
import * as SentryNode from '@sentry/node';
12+
import * as SentryCore from '@sentry/core';
1313
import type { Handle } from '@sveltejs/kit';
1414
import { redirect } from '@sveltejs/kit';
1515
import { vi } from 'vitest';
1616

1717
import { FETCH_PROXY_SCRIPT, addSentryCodeToPage } from '../../src/server-common/handle';
18-
import { sentryHandle } from '../../src/server/handle';
18+
import { sentryHandle } from '../../src/server-common/handle';
1919
import { getDefaultNodeClientOptions } from '../utils';
2020

21-
const mockCaptureException = vi.spyOn(SentryNode, 'captureException').mockImplementation(() => 'xx');
21+
const mockCaptureException = vi.spyOn(SentryCore, 'captureException').mockImplementation(() => 'xx');
2222

2323
function mockEvent(override: Record<string, unknown> = {}): Parameters<Handle>[0]['event'] {
2424
const event: Parameters<Handle>[0]['event'] = {
@@ -442,7 +442,7 @@ describe('addSentryCodeToPage', () => {
442442

443443
it('adds meta tags and the fetch proxy script if there is an active transaction', () => {
444444
const transformPageChunk = addSentryCodeToPage({});
445-
SentryNode.startSpan({ name: 'test' }, () => {
445+
SentryCore.startSpan({ name: 'test' }, () => {
446446
const transformed = transformPageChunk({ html, done: true }) as string;
447447

448448
expect(transformed).toContain('<meta name="sentry-trace"');
@@ -454,7 +454,7 @@ describe('addSentryCodeToPage', () => {
454454

455455
it('adds a nonce attribute to the script if the `fetchProxyScriptNonce` option is specified', () => {
456456
const transformPageChunk = addSentryCodeToPage({ fetchProxyScriptNonce: '123abc' });
457-
SentryNode.startSpan({ name: 'test' }, () => {
457+
SentryCore.startSpan({ name: 'test' }, () => {
458458
const transformed = transformPageChunk({ html, done: true }) as string;
459459

460460
expect(transformed).toContain('<meta name="sentry-trace"');

packages/sveltekit/test/server/handleError.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest';
22

3-
import * as SentryNode from '@sentry/node';
3+
import * as SentryCore from '@sentry/core';
44
import type { HandleServerError, RequestEvent } from '@sveltejs/kit';
55

66
import { handleErrorWithSentry } from '../../src/server-common/handleError';
77

8-
const mockCaptureException = vi.spyOn(SentryNode, 'captureException').mockImplementation(() => 'xx');
8+
const mockCaptureException = vi.spyOn(SentryCore, 'captureException').mockImplementation(() => 'xx');
99

1010
const captureExceptionEventHint = {
1111
mechanism: { handled: false, type: 'sveltekit' },

packages/sveltekit/test/server/load.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import {
77
} from '@sentry/core';
88
import type { Event } from '@sentry/core';
99
import { NodeClient, getCurrentScope, getIsolationScope, setCurrentClient } from '@sentry/node';
10-
import * as SentryNode from '@sentry/node';
10+
import * as SentryCore from '@sentry/core';
1111
import type { Load, ServerLoad } from '@sveltejs/kit';
1212
import { error, redirect } from '@sveltejs/kit';
1313

1414
import { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../../src/server-common/load';
1515
import { getDefaultNodeClientOptions } from '../utils';
1616

17-
const mockCaptureException = vi.spyOn(SentryNode, 'captureException').mockImplementation(() => 'xx');
17+
const mockCaptureException = vi.spyOn(SentryCore, 'captureException').mockImplementation(() => 'xx');
1818

1919
const mockStartSpan = vi.fn();
2020

packages/sveltekit/test/server/serverRoute.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as SentryNode from '@sentry/node';
1+
import * as SentryCore from '@sentry/core';
22
import type { NumericRange } from '@sveltejs/kit';
33
import { type RequestEvent, error, redirect } from '@sveltejs/kit';
44
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -26,7 +26,7 @@ describe('wrapServerRouteWithSentry', () => {
2626
});
2727

2828
describe('wraps a server route span around the original server route handler', () => {
29-
const startSpanSpy = vi.spyOn(SentryNode, 'startSpan');
29+
const startSpanSpy = vi.spyOn(SentryCore, 'startSpan');
3030

3131
it('assigns the route id as name if available', () => {
3232
const wrappedRouteHandler = wrapServerRouteWithSentry(originalRouteHandler);
@@ -71,7 +71,7 @@ describe('wrapServerRouteWithSentry', () => {
7171
});
7272
});
7373

74-
const captureExceptionSpy = vi.spyOn(SentryNode, 'captureException');
74+
const captureExceptionSpy = vi.spyOn(SentryCore, 'captureException');
7575
describe('captures server route errors', () => {
7676
it('captures and rethrows normal server route error', async () => {
7777
const error = new Error('Server Route Error');

0 commit comments

Comments
 (0)