-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathjest.setup.ts
72 lines (65 loc) · 1.77 KB
/
jest.setup.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { jest } from '@jest/globals';
import FirecrawlApp from '@mendable/firecrawl-js';
import type {
SearchResponse,
BatchScrapeResponse,
BatchScrapeStatusResponse,
FirecrawlDocument,
} from '@mendable/firecrawl-js';
// Set test timeout
jest.setTimeout(30000);
// Create mock responses
const mockSearchResponse: SearchResponse = {
success: true,
data: [
{
url: 'https://example.com',
title: 'Test Page',
description: 'Test Description',
markdown: '# Test Content',
actions: null as never,
},
] as FirecrawlDocument<undefined, never>[],
};
const mockBatchScrapeResponse: BatchScrapeResponse = {
success: true,
id: 'test-batch-id',
};
const mockBatchStatusResponse: BatchScrapeStatusResponse = {
success: true,
status: 'completed',
completed: 1,
total: 1,
creditsUsed: 1,
expiresAt: new Date(),
data: [
{
url: 'https://example.com',
title: 'Test Page',
description: 'Test Description',
markdown: '# Test Content',
actions: null as never,
},
] as FirecrawlDocument<undefined, never>[],
};
// Create mock instance methods
const mockSearch = jest.fn().mockImplementation(async () => mockSearchResponse);
const mockAsyncBatchScrapeUrls = jest
.fn()
.mockImplementation(async () => mockBatchScrapeResponse);
const mockCheckBatchScrapeStatus = jest
.fn()
.mockImplementation(async () => mockBatchStatusResponse);
// Create mock instance
const mockInstance = {
apiKey: 'test-api-key',
apiUrl: 'test-api-url',
search: mockSearch,
asyncBatchScrapeUrls: mockAsyncBatchScrapeUrls,
checkBatchScrapeStatus: mockCheckBatchScrapeStatus,
};
// Mock the module
jest.mock('@mendable/firecrawl-js', () => ({
__esModule: true,
default: jest.fn().mockImplementation(() => mockInstance),
}));