Skip to content

Commit

Permalink
Increase timeouts in tests
Browse files Browse the repository at this point in the history
refactor voiceMessage tests
delete coverage test before pushing
  • Loading branch information
Rei-x committed May 20, 2021
1 parent 98560ec commit be1fb12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint && npm run coverage
npm run lint
2 changes: 1 addition & 1 deletion tests/discordSR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('DiscordSR tests', function() {
});

it('Default speech recognition', async function() {
this.timeout(6000);
this.timeout(7000);

await tm.clientVoiceChannel.join();
const testConnection = await tm.testVoiceChannel.join();
Expand Down
11 changes: 6 additions & 5 deletions tests/voiceMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Voice message', function() {
}, undefined);
});
it('Save to .wav file', async function() {
this.timeout(4000);
voiceMessage.saveToFile(filename);
expect(fs.existsSync(filename));
const readAudioBuffer = await readFileToAudioBuffer(filename);
Expand All @@ -39,10 +40,10 @@ async function readFileToAudioBuffer(filename: fs.PathLike): Promise<Buffer> {
const buffs: Uint8Array[] = [];
const pcmDataStream = createWritable();

writeAudioDataToFile();
writeAudioDataToWavStream(file, pcmDataStream);

return new Promise<Buffer>((resolve) => {
pcmDataStream.on('close', () => {
pcmDataStream.on('finish', () => {
const audioBuffer = Buffer.concat(buffs);
resolve(audioBuffer);
});
Expand All @@ -58,12 +59,12 @@ async function readFileToAudioBuffer(filename: fs.PathLike): Promise<Buffer> {
});
}

function writeAudioDataToFile() {
function writeAudioDataToWavStream(stream: fs.ReadStream, streamReader: Writable) {
const reader = new wav.Reader();
reader.on('format', () => {
reader.pipe(pcmDataStream);
reader.pipe(streamReader);
});
file.pipe(reader);
stream.pipe(reader);
}
}

0 comments on commit be1fb12

Please sign in to comment.