Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Nov 27, 2023
1 parent 80094df commit b7588e9
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 68 deletions.
10 changes: 6 additions & 4 deletions binding/react/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { WebVoiceProcessor } from '@picovoice/web-voice-processor';
import { act } from '@testing-library/react-hooks/dom';

const WAV_HEADER_SIZE = 44;

Cypress.Commands.add('wrapHook', (fn: () => Promise<void>) =>
cy.wrap(null).then(async () => {
await act(async () => {
Expand All @@ -15,7 +17,7 @@ Cypress.Commands.add('getFileObj', (path: string) => {
.then(blob => new File([blob], 'test_audio'));
});

Cypress.Commands.add('mockRecording', (path: string, delayMs = 1000) => {
Cypress.Commands.add('mockRecording', (path: string) => {
// @ts-ignore
const instance = WebVoiceProcessor.instance();

Expand All @@ -26,12 +28,12 @@ Cypress.Commands.add('mockRecording', (path: string, delayMs = 1000) => {
cy.fixture(path, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(async blob => {
const data = new Int16Array(await blob.arrayBuffer());
let data = new Int16Array(await blob.arrayBuffer());
data = data.slice(WAV_HEADER_SIZE / Int16Array.BYTES_PER_ELEMENT);
for (let i = 0; i < data.length; i += 512) {
instance.recorderCallback(data.slice(i, i + 512));
}
})
.wait(delayMs);
});

instance._microphoneStream?.getAudioTracks().forEach((track: any) => {
track.enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion binding/react/cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare global {
interface Chainable {
wrapHook(fn: () => Promise<any>): Chainable<void>;

Check warning on line 6 in binding/react/cypress/support/index.ts

View workflow job for this annotation

GitHub Actions / check-react-codestyle

'fn' is defined but never used
getFileObj(path: string): Chainable<File>;

Check warning on line 7 in binding/react/cypress/support/index.ts

View workflow job for this annotation

GitHub Actions / check-react-codestyle

'path' is defined but never used
mockRecording(path: string, delayMs?: number): Chainable<void>;
mockRecording(path: string): Chainable<void>;

Check warning on line 8 in binding/react/cypress/support/index.ts

View workflow job for this annotation

GitHub Actions / check-react-codestyle

'path' is defined but never used
}
}
}
Loading

0 comments on commit b7588e9

Please sign in to comment.