Skip to content

Commit ed92ca7

Browse files
committed
test refactors
1 parent e95408c commit ed92ca7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/cloudflare/test/handler.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Note: These tests run the handler in Node.js, which is has some differences to the cloudflare workers runtime.
1+
// Note: These tests run the handler in Node.js, which has some differences to the cloudflare workers runtime.
22
// Although this is not ideal, this is the best we can do until we have a better way to test cloudflare workers.
33

44
import { beforeEach, describe, expect, test, vi } from 'vitest';
@@ -69,9 +69,9 @@ describe('withSentry', () => {
6969
});
7070

7171
test('creates a cloudflare client and sets it on the handler', async () => {
72+
const initAndBindSpy = vi.spyOn(SentryCore, 'initAndBind');
7273
const handler = {
7374
async fetch(_request, _env, _context) {
74-
expect(SentryCore.getClient() instanceof CloudflareClient).toBe(true);
7575
return new Response('test');
7676
},
7777
} satisfies ExportedHandler;
@@ -80,7 +80,8 @@ describe('withSentry', () => {
8080
const wrappedHandler = withSentry(() => ({}), handler);
8181
await wrappedHandler.fetch(new Request('https://example.com'), MOCK_ENV, context);
8282

83-
expect.assertions(1);
83+
expect(initAndBindSpy).toHaveBeenCalledTimes(1);
84+
expect(initAndBindSpy).toHaveBeenLastCalledWith(CloudflareClient, expect.any(Object));
8485
});
8586

8687
describe('scope instrumentation', () => {
@@ -180,7 +181,9 @@ describe('withSentry', () => {
180181
// ignore
181182
}
182183
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
183-
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, { mechanism: { handled: false } });
184+
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
185+
mechanism: { handled: false, type: 'cloudflare' },
186+
});
184187
});
185188

186189
test('re-throws the error after capturing', async () => {

0 commit comments

Comments
 (0)