Skip to content

Commit

Permalink
test: separate test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
amishshah committed Apr 5, 2018
1 parent e87e1d7 commit 371d243
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 81 deletions.
29 changes: 29 additions & 0 deletions test/ffmpeg.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable */

const fs = require('fs');
const prism = require('../');
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
const { roughlyEquals, streamToBuffer } = require('./util');

test('FFmpeg transcoder available', () => {
expect(prism.FFmpeg).toBeTruthy();
});

test('FFmpeg transcoder to PCM is sane', async done => {
expect.assertions(1);
const output = fs.createReadStream('./test/audio/speech_orig.ogg')
.pipe(new prism.FFmpeg({
args: [
'-analyzeduration', '0',
'-loglevel', '0',
'-f', 's16le',
'-ar', '48000',
'-ac', '2',
],
}));
const chunks = await streamToBuffer(output);
const file = await readFile('./test/audio/speech_orig.pcm');
expect(roughlyEquals(file, chunks)).toEqual(true);
done();
});
32 changes: 32 additions & 0 deletions test/opus.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable */

const fs = require('fs');
const prism = require('../');
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
const { roughlyEquals, streamToBuffer } = require('./util');

test('OggOpus Demuxer available', () => {
expect(prism.OggOpusDemuxer).toBeTruthy();
});

test('WebmOpus Demuxer available', () => {
expect(prism.WebmOpusDemuxer).toBeTruthy();
expect(prism.WebmOpusDemuxer.TOO_SHORT).toBeTruthy();
expect(prism.WebmOpusDemuxer.TAGS).toBeTruthy();
});

test('Opus encoders/decoders available', () => {
expect(prism.opus).toBeTruthy();
expect(prism.opus.Encoder).toBeTruthy();
expect(prism.opus.Decoder).toBeTruthy();
});

test('OggOpus demuxer is sane', async done => {
expect.assertions(1);
const output = fs.createReadStream('./test/audio/speech_orig.ogg').pipe(new prism.OggOpusDemuxer());
const chunks = await streamToBuffer(output);
const file = await readFile('./test/audio/speech_orig.opusdump');
expect(roughlyEquals(file, chunks)).toEqual(true);
done();
});
81 changes: 0 additions & 81 deletions test/test.js

This file was deleted.

19 changes: 19 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// The output is slightly different on travis because of ffmpeg version, should account for it
exports.roughlyEquals = function roughlyEquals(x, y) {
if (x.length !== y.length) return false;
for (let i = 0; i < x.length; i++) {
if (Math.abs(x[i] - y[i]) > 1) {
return false;
}
}
return true;
};

exports.streamToBuffer = function streamToBuffer(stream) {
return new Promise((resolve, reject) => {
let chunks = [];
stream.on('data', chunk => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(Buffer.concat(chunks)));
});
};
10 changes: 10 additions & 0 deletions test/volumetransform.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */

const prism = require('../');

test('Volume Transformers available', () => {
expect(prism.VolumeTransformer16LE).toBeTruthy();
expect(prism.VolumeTransformer16BE).toBeTruthy();
expect(prism.VolumeTransformer32LE).toBeTruthy();
expect(prism.VolumeTransformer32BE).toBeTruthy();
});

0 comments on commit 371d243

Please sign in to comment.