Skip to content

Commit b2c6e5c

Browse files
authored
Mock PCMRecorder
1 parent a35fd60 commit b2c6e5c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/bundle/src/createCognitiveServicesSpeechServicesPonyfillFactory.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
*/
88
/* eslint-disable prefer-destructuring */
99
/* eslint-disable no-global-assign */
10-
import random from 'math-random';
11-
1210
let consoleWarns;
1311
let createCognitiveServicesSpeechServicesPonyfillFactory;
1412
let createPonyfill;
1513
let originalConsole;
1614

1715
beforeEach(() => {
1816
jest.mock('web-speech-cognitive-services/lib/SpeechServices', () => jest.fn(() => ({})));
17+
jest.mock('microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.browser/Exports', () => ({
18+
...jest.requireActual('microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.browser/Exports'),
19+
PcmRecorder: class MockPcmRecorder {
20+
// eslint-disable-next-line class-methods-use-this, no-empty-function
21+
record() {}
22+
// eslint-disable-next-line class-methods-use-this, no-empty-function
23+
releaseMediaResources() {}
24+
// eslint-disable-next-line class-methods-use-this, no-empty-function
25+
setWorkletUrl() {}
26+
}
27+
}));
1928

2029
originalConsole = console;
2130
consoleWarns = [];
@@ -43,15 +52,6 @@ beforeEach(() => {
4352
}
4453
};
4554

46-
window.URL = {
47-
...window.URL,
48-
// Even when AudioContext does not support audio worklet, PCMRecorder always create it via URL.createObjectURL().
49-
// As JSDOM does not support URL.createObjectURL(), we need to return a dummy blob URL.
50-
// https://github.com/microsoft/cognitive-services-speech-sdk-js/issues/572
51-
// eslint-disable-next-line no-magic-numbers
52-
createObjectURL: () => `blob:${random().toString(36).substring(2)}`
53-
};
54-
5555
window.navigator.mediaDevices = {
5656
getUserMedia: jest.fn(() => ({
5757
getAudioTracks: () => ['mock-media-stream-track']

0 commit comments

Comments
 (0)