-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathpages-plugin.test.ts
36 lines (29 loc) · 1.13 KB
/
pages-plugin.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Note: These tests run the handler in Node.js, which has some differences to the cloudflare workers runtime.
// Although this is not ideal, this is the best we can do until we have a better way to test cloudflare workers.
import { beforeEach, describe, expect, test, vi } from 'vitest';
import type { CloudflareOptions } from '../src/client';
import { sentryPagesPlugin } from '../src/pages-plugin';
const MOCK_OPTIONS: CloudflareOptions = {
dsn: 'https://[email protected]/1337',
};
describe('sentryPagesPlugin', () => {
beforeEach(() => {
vi.clearAllMocks();
});
test('passes through the response from the handler', async () => {
const response = new Response('test');
const mockOnRequest = sentryPagesPlugin(MOCK_OPTIONS);
const result = await mockOnRequest({
request: new Request('https://example.com'),
functionPath: 'test',
waitUntil: vi.fn(),
passThroughOnException: vi.fn(),
next: () => Promise.resolve(response),
env: { ASSETS: { fetch: vi.fn() } },
params: {},
data: {},
pluginArgs: MOCK_OPTIONS,
});
expect(result).toBe(response);
});
});