-
Notifications
You must be signed in to change notification settings - Fork 3
/
jestSetup.ts
144 lines (137 loc) · 3.63 KB
/
jestSetup.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* eslint-disable import/no-extraneous-dependencies */
import '@testing-library/jest-dom';
/* We define this here (outside of beforeAll) to ensure the Core SDK is able to load our extensions before the test suites run */
Object.defineProperty(window, 'MediaStream', {
writable: true,
value: jest.fn(),
});
beforeAll(() => {
const audioTracks = [
{
id: 'audio-track-1',
applyConstraints: jest.fn(),
getCapabilities: jest.fn().mockReturnValue({
deviceId: 'audio-1',
sampleRate: 44100,
sampleSize: 16,
channelCount: 1,
}),
getSettings: jest.fn().mockReturnValue({
sampleRate: 44100,
sampleSize: 16,
channelCount: 1,
}),
stop: jest.fn(),
},
{
id: 'audio-track-2',
applyConstraints: jest.fn(),
getCapabilities: jest.fn().mockReturnValue({
deviceId: 'audio-2',
sampleRate: 48000,
sampleSize: 32,
channelCount: 2,
}),
getSettings: jest.fn().mockReturnValue({
sampleRate: 48000,
sampleSize: 32,
channelCount: 2,
}),
stop: jest.fn(),
},
];
const videoTracks = [
{
id: 'video-track-1',
applyConstraints: jest.fn(),
getCapabilities: jest.fn().mockReturnValue({
deviceId: 'video-1',
frameRate: 30,
height: 720,
width: 1280,
}),
getSettings: jest.fn().mockReturnValue({
frameRate: 30,
height: 720,
width: 1280,
}),
stop: jest.fn(),
},
{
id: 'video-track-2',
applyConstraints: jest.fn(),
getCapabilities: jest.fn().mockReturnValue({
deviceId: 'video-2',
frameRate: 60,
height: 1080,
width: 1920,
}),
getSettings: jest.fn().mockReturnValue({
frameRate: 60,
height: 1080,
width: 1920,
}),
stop: jest.fn(),
},
];
Object.defineProperty(window.navigator, 'mediaDevices', {
writable: true,
value: {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
enumerateDevices: jest.fn().mockResolvedValue([
{
deviceId: 'audio-1',
kind: 'audioinput',
},
{
deviceId: 'audio-2',
kind: 'audioinput',
},
{
deviceId: 'video-1',
kind: 'videoinput',
},
{
deviceId: 'video-2',
kind: 'videoinput',
},
{
deviceId: 'audio-output-1',
kind: 'audiooutput',
},
{
deviceId: 'audio-output-2',
kind: 'audiooutput',
},
]),
getUserMedia: jest.fn().mockResolvedValue({
get getTrackById() {
return jest
.fn()
.mockImplementation((id) =>
this.getTracks().find((track: MediaStreamTrack) => id === track.id)
);
},
getTracks: jest.fn().mockReturnValue([...audioTracks, ...videoTracks]),
getAudioTracks: jest.fn().mockReturnValue([...audioTracks]),
getVideoTracks: jest.fn().mockReturnValue([...videoTracks]),
}),
},
});
Object.defineProperty(window, 'MediaRecorder', {
writable: true,
value: jest.fn().mockImplementation(() => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
mimeType: 'video/webm;codecs=vp9,opus',
start: jest.fn(),
stop: jest.fn(),
state: 'inactive',
isTypeSupported: jest.fn().mockReturnValue(true),
})),
});
MediaRecorder.isTypeSupported = jest.fn().mockReturnValue(true);
window.URL.createObjectURL = jest.fn();
window.URL.revokeObjectURL = jest.fn();
});