Skip to content

Commit

Permalink
add lamejs plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Apr 30, 2018
1 parent 12fa32d commit f257b95
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 19 deletions.
6 changes: 5 additions & 1 deletion karma.conf.js
Expand Up @@ -55,14 +55,18 @@ module.exports = function(config) {
'node_modules/videojs-wavesurfer/dist/css/videojs.wavesurfer.css',
'dist/css/videojs.record.css',

// dependencies
// library dependencies
'node_modules/video.js/dist/video.js',
'node_modules/webrtc-adapter/out/adapter.js',
'node_modules/recordrtc/RecordRTC.js',
'node_modules/wavesurfer.js/dist/wavesurfer.js',
'node_modules/wavesurfer.js/dist/plugin/wavesurfer.microphone.js',
'node_modules/videojs-wavesurfer/dist/videojs.wavesurfer.js',

// optional library dependencies for plugins
{pattern: 'node_modules/lamejs/worker-example/*worker*.js', included: false},
'node_modules/lamejs/lame.min.js',

// specs
'test/**/*.spec.js'
],
Expand Down
52 changes: 52 additions & 0 deletions test/plugins/lamejs-plugin.spec.js
@@ -0,0 +1,52 @@
/**
* @since 2.2.0
*/

import TestHelpers from '../test-helpers.js';

// registers the plugin
import LamejsEngine from '../../src/js/plugins/lamejs-plugin.js';
import {LAMEJS} from '../../src/js/engine/record-engine.js';


/** @test {LamejsEngine} */
describe('plugins.lamejs-plugin', function() {
var player;

afterEach(function() {
player.dispose();
});

/** @test {LamejsEngine} */
it('should run as an audio-only plugin', function(done) {
// create audio-only player with lamejs plugin
player = TestHelpers.makeAudioOnlyPluginPlayer(LAMEJS);

player.one('finishRecord', function() {
// received a blob file
expect(player.recordedData instanceof Blob).toBeTruthy();

// wait till it's loaded before destroying
// (XXX: create new event for this)
setTimeout(done, 1000);
});

player.one('startRecord', function() {
// record some audio
setTimeout(function() {
// stop
player.record().stop();
}, 2000);
});

player.one('deviceReady', function() {
// create snapshot
player.record().start();
});

player.one('ready', function() {
// start device
player.record().getDevice();
});
});
});
63 changes: 45 additions & 18 deletions test/test-helpers.js
Expand Up @@ -6,10 +6,22 @@ import document from 'global/document';

import Player from 'video.js';

import {LIBVORBISJS, RECORDERJS, LAMEJS, OPUSRECORDER} from '../src/js/engine/record-engine.js';


const TestHelpers = {
TEST_OGG: '/base/test/support/audio.ogg',

DEFAULT_WAVESURFER_OPTIONS: {
src: 'live',
waveColor: '#36393b',
progressColor: 'black',
debug: true,
cursorWidth: 1,
msDisplayMax: 20,
hideScrollbar: true
},

/**
* Create DOM element.
*/
Expand Down Expand Up @@ -50,15 +62,7 @@ const TestHelpers = {
width: 600,
height: 300,
plugins: {
wavesurfer: {
src: "live",
waveColor: "#36393b",
progressColor: "black",
debug: true,
cursorWidth: 1,
msDisplayMax: 20,
hideScrollbar: true
},
wavesurfer: this.DEFAULT_WAVESURFER_OPTIONS,
record: {
audio: true,
video: false,
Expand All @@ -81,15 +85,7 @@ const TestHelpers = {
width: 500,
height: 400,
plugins: {
wavesurfer: {
src: "live",
waveColor: "#36393b",
progressColor: "black",
debug: true,
cursorWidth: 1,
msDisplayMax: 20,
hideScrollbar: true
},
wavesurfer: this.DEFAULT_WAVESURFER_OPTIONS,
record: {
audio: true,
video: false,
Expand All @@ -100,6 +96,37 @@ const TestHelpers = {
});
},

makeAudioOnlyPluginPlayer(pluginName) {
var tag = TestHelpers.makeTag('audio', 'audioOnly');
var recordPluginOptions = {
audio: true,
video: false,
maxLength: 5,
debug: true
};
// setup audio plugin
switch (pluginName) {
case LAMEJS:
recordPluginOptions.audioEngine = LAMEJS;
recordPluginOptions.audioWorkerURL = '/base/node_modules/lamejs/worker-example/worker-realtime.js';
recordPluginOptions.audioSampleRate = 44100;
recordPluginOptions.audioBitRate = 128;
break;
}
return this.makePlayer(tag, {
controls: true,
autoplay: false,
fluid: false,
loop: false,
width: 600,
height: 350,
plugins: {
wavesurfer: this.DEFAULT_WAVESURFER_OPTIONS,
record: recordPluginOptions
}
});
},

makeVideoOnlyPlayer() {
var tag = TestHelpers.makeTag('video', 'videoOnly');
return this.makePlayer(tag, {
Expand Down

0 comments on commit f257b95

Please sign in to comment.