Skip to content

Commit 9617647

Browse files
committed
fix tests
1 parent 4d49212 commit 9617647

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/sveltekit/src/server/load.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @sentry-internal/sdk/no-optional-chaining */
2-
import { getCurrentHub, startSpan, trace } from '@sentry/core';
2+
import { flush, getCurrentHub, startSpan, trace } from '@sentry/core';
33
import { captureException } from '@sentry/node';
44
import type { TransactionContext } from '@sentry/types';
55
import { addExceptionMechanism, addNonEnumerableProperty, objectify } from '@sentry/utils';
@@ -153,12 +153,13 @@ export function wrapServerLoadWithSentry<T extends (...args: any) => any>(origSe
153153
};
154154

155155
try {
156-
const serverLoadResult = startSpan(traceLoadContext, () => wrappingTarget.apply(thisArg, args));
156+
const serverLoadResult = await startSpan(traceLoadContext, () => wrappingTarget.apply(thisArg, args));
157157
return serverLoadResult;
158158
} catch (e: unknown) {
159159
sendErrorToSentry(e);
160160
throw e;
161161
} finally {
162+
await flush(4000);
162163
await flushIfServerless();
163164
}
164165
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ vi.mock('@sentry/node', async () => {
2323
};
2424
});
2525

26-
const mockAddExceptionMechanism = vi.fn(() => console.trace());
26+
const mockAddExceptionMechanism = vi.fn();
2727

2828
vi.mock('@sentry/utils', async () => {
2929
const original = (await vi.importActual('@sentry/utils')) as any;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ afterEach(() => {
134134
mockAddExceptionMechanism.mockClear();
135135
mockStartSpan.mockClear();
136136
mockScope = new Scope();
137-
// @ts-expect-error - this is fine (just tests here)
138-
mockScope.mockClear?.call(mockScope);
139137
});
140138

141139
describe.each([
@@ -195,12 +193,12 @@ describe.each([
195193
expect(mockCaptureException).not.toHaveBeenCalled();
196194
});
197195

198-
vi.spyOn(mockScope, 'addEventProcessor').mockImplementationOnce(callback => {
199-
void callback({}, { event_id: 'fake-event-id' });
200-
return mockScope;
201-
});
196+
it('adds an exception mechanism', async () => {
197+
vi.spyOn(mockScope, 'addEventProcessor').mockImplementationOnce(callback => {
198+
void callback({}, { event_id: 'fake-event-id' });
199+
return mockScope;
200+
});
202201

203-
it.only('adds an exception mechanism', async () => {
204202
async function load({ params }) {
205203
return {
206204
post: getById(params.id),
@@ -212,7 +210,7 @@ describe.each([
212210
await expect(res).rejects.toThrow();
213211

214212
// expect(addEventProcessorSpy).toHaveBeenCalledTimes(1);
215-
expect(mockAddExceptionMechanism).toHaveBeenCalledTimes(1);
213+
expect(mockAddExceptionMechanism).toBeCalledTimes(1);
216214
expect(mockAddExceptionMechanism).toBeCalledWith(
217215
{},
218216
{ handled: false, type: 'sveltekit', data: { function: 'load' } },

0 commit comments

Comments
 (0)