-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
75 lines (67 loc) · 1.67 KB
/
jest.setup.js
File metadata and controls
75 lines (67 loc) · 1.67 KB
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
// Jest setup file
require('@testing-library/jest-dom');
// Mock browser objects and globals
global.document = document;
global.window = window;
global.navigator = {
userAgent: 'node.js',
mediaDevices: {
getUserMedia: jest.fn()
}
};
// Mock console methods to avoid cluttering test output
console.log = jest.fn();
console.warn = jest.fn();
console.error = jest.fn();
// Mock audio context
class AudioContext {
constructor() {
this.createAnalyser = jest.fn().mockReturnValue({
connect: jest.fn(),
disconnect: jest.fn(),
fftSize: 0,
getByteFrequencyData: jest.fn()
});
this.createMediaStreamSource = jest.fn().mockReturnValue({
connect: jest.fn()
});
this.createGain = jest.fn().mockReturnValue({
connect: jest.fn(),
gain: { value: 1.0 }
});
this.createScriptProcessor = jest.fn().mockReturnValue({
connect: jest.fn(),
disconnect: jest.fn(),
addEventListener: jest.fn()
});
this.destination = {};
}
}
global.AudioContext = AudioContext;
global.webkitAudioContext = AudioContext;
// Mock HTMLMediaElement methods
HTMLMediaElement.prototype.pause = jest.fn();
HTMLMediaElement.prototype.play = jest.fn();
// Mock ProtoBuf
global.protobuf = {
load: jest.fn((path, callback) => {
callback(null, {
lookupType: jest.fn().mockReturnValue({})
});
})
};
// Setup global test objects
global.AI_CONFIG = {
SAMPLE_RATE: 16000,
NUM_CHANNELS: 1,
SPEECH_THRESHOLD: 0.03,
REQUIRED_CONSECUTIVE_FRAMES: 4,
Frame: null,
initProtobuf: jest.fn().mockResolvedValue({})
};
global.AI_STATE = {
isPlaying: false,
isAIResponding: false,
isBeingInterrupted: false,
silenceTimeout: null
};