-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
78 lines (68 loc) · 2.2 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
73
74
75
76
77
78
// add global mocks here
import 'web-streams-polyfill';
global.ReadableStream = jest.fn().mockImplementation(() => ({
// mock methods you use in your test
getReader: jest.fn(),
}));
// mock react-audio-voice-recorder used in VoiceChatButton
jest.mock('react-audio-voice-recorder');
import { useAudioRecorder } from 'react-audio-voice-recorder';
(useAudioRecorder as jest.Mock).mockReturnValue({
isRecording: false,
recordingBlob: new Blob(['test'], { type: 'audio/wav' }),
startRecording: jest.fn(),
stopRecording: jest.fn(() => new Blob(['test'], { type: 'audio/wav' })),
});
// mock @langchain/core/runnables
jest.mock('@langchain/core/runnables');
import { Runnable } from '@langchain/core/runnables';
(Runnable as unknown as jest.Mock).mockReturnValue({
invoke: jest.fn(),
stream: jest.fn(),
});
// mock @langchain/google-genai
jest.mock('@langchain/google-genai');
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
// mock the ChatGoogleGenerativeAI class
(ChatGoogleGenerativeAI as unknown as jest.Mock).mockReturnValue({
call: jest.fn(),
bindTools: jest.fn(),
invoke: jest.fn(),
});
// mock @langchain/ollama
jest.mock('@langchain/ollama');
import { ChatOllama } from '@langchain/ollama';
// mock the ChatOllama class
(ChatOllama as unknown as jest.Mock).mockReturnValue({
call: jest.fn(),
bind: jest.fn(),
});
// // mock openai
// jest.mock('openai');
// import OpenAI from '../__mocks__/openai';
// (OpenAI as unknown as jest.Mock).mockReturnValue({
// create: jest.fn(),
// });
// export const mockMutexRelease = jest.fn();
// jest.mock('async-mutex', () => ({
// Mutex: jest.fn().mockImplementation(() => ({
// acquire: jest.fn().mockResolvedValue(mockMutexRelease),
// })),
// }));
// // Mock FileReader
// class MockFileReader {
// onload: () => void = () => {};
// result: string = 'mock file content';
// readAsText(blob: Blob) {
// setTimeout(() => {
// this.onload();
// }, 0);
// }
// readAsDataURL(blob: Blob) {
// setTimeout(() => {
// this.result = 'data:text/plain;base64,bW9jayBmaWxlIGNvbnRlbnQ='; // base64 encoded "mock file content"
// this.onload();
// }, 0);
// }
// }
// global.FileReader = MockFileReader as any;