Skip to content

Commit

Permalink
tests: update all lib tests to use new shared resources
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed May 22, 2017
1 parent 5c9ca0e commit 8bf27f3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 72 deletions.
45 changes: 22 additions & 23 deletions test/unit/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ require('../common/bootstrap');

exports['av.Camera'] = {
setUp(done) {
this.sandbox = sinon.sandbox.create();
this.emitter = new Emitter();
this.spawn = this.sandbox.stub(cp, 'spawn').callsFake(() => {
this.spawn = sandbox.stub(cp, 'spawn').callsFake(() => {
this.emitter = new Emitter();
this.emitter.kill = this.sandbox.stub();
this.emitter.kill = sandbox.stub();
this.emitter.stderr = new Emitter();
this.emitter.stdout = new Emitter();
return this.emitter;
});

this.wmSet = this.sandbox.spy(WeakMap.prototype, 'set');
this.write = this.sandbox.stub(Writable.prototype, 'write');
this.wmSet = sandbox.spy(WeakMap.prototype, 'set');
this.write = sandbox.stub(Writable.prototype, 'write');

done();
},

tearDown(done) {
this.sandbox.restore();
sandbox.restore();
done();
},

Expand Down Expand Up @@ -199,8 +198,8 @@ exports['av.Camera'] = {
const cam = new av.Camera();
const writable = new Writable();

this.sandbox.spy(cam, 'capture');
this.sandbox.spy(cam, 'stream');
sandbox.spy(cam, 'capture');
sandbox.spy(cam, 'stream');

cam.on('stop', () => {
test.ok(buffer.equals(buffer));
Expand Down Expand Up @@ -258,7 +257,7 @@ exports['av.Camera'] = {
streamError(test) {
test.expect(11);

this.sandbox.spy(av.Camera.prototype, 'stream');
sandbox.spy(av.Camera.prototype, 'stream');

const streams = {
a: new Emitter(),
Expand All @@ -271,11 +270,11 @@ exports['av.Camera'] = {
state.process = null;
state.stream = null;

streams.b.pipe = this.sandbox.stub();
streams.a.pipe = this.sandbox.stub().callsFake(() => streams.b);
streams.b.pipe = sandbox.stub();
streams.a.pipe = sandbox.stub().callsFake(() => streams.b);

this.sandbox.stub(got, 'stream').callsFake(() => streams.a);
this.sandbox.spy(state.remote, 'start');
sandbox.stub(got, 'stream').callsFake(() => streams.a);
sandbox.spy(state.remote, 'start');

test.equal(cam.stream.callCount, 1);
test.equal(got.stream.callCount, 0);
Expand Down Expand Up @@ -304,7 +303,7 @@ exports['av.Camera'] = {
streamData(test) {
test.expect(13);

this.sandbox.spy(av.Camera.prototype, 'stream');
sandbox.spy(av.Camera.prototype, 'stream');

const streams = {
a: new Emitter(),
Expand All @@ -317,11 +316,11 @@ exports['av.Camera'] = {
state.process = null;
state.stream = null;

streams.b.pipe = this.sandbox.stub();
streams.a.pipe = this.sandbox.stub().callsFake(() => streams.b);
streams.b.pipe = sandbox.stub();
streams.a.pipe = sandbox.stub().callsFake(() => streams.b);

this.sandbox.stub(got, 'stream').callsFake(() => streams.a);
this.sandbox.spy(state.remote, 'start');
sandbox.stub(got, 'stream').callsFake(() => streams.a);
sandbox.spy(state.remote, 'start');

test.equal(cam.stream.callCount, 1);
test.equal(got.stream.callCount, 0);
Expand Down Expand Up @@ -355,7 +354,7 @@ exports['av.Camera'] = {
streamDataError(test) {
test.expect(11);

this.sandbox.spy(av.Camera.prototype, 'stream');
sandbox.spy(av.Camera.prototype, 'stream');

const streams = {
a: new Emitter(),
Expand All @@ -368,11 +367,11 @@ exports['av.Camera'] = {
state.process = null;
state.stream = null;

streams.b.pipe = this.sandbox.stub();
streams.a.pipe = this.sandbox.stub().callsFake(() => streams.b);
streams.b.pipe = sandbox.stub();
streams.a.pipe = sandbox.stub().callsFake(() => streams.b);

this.sandbox.stub(got, 'stream').callsFake(() => streams.a);
this.sandbox.spy(state.remote, 'start');
sandbox.stub(got, 'stream').callsFake(() => streams.a);
sandbox.spy(state.remote, 'start');

test.equal(cam.stream.callCount, 1);
test.equal(got.stream.callCount, 0);
Expand Down
31 changes: 15 additions & 16 deletions test/unit/microphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ require('../common/bootstrap');

exports['av.Microphone'] = {
setUp(done) {
this.sandbox = sinon.sandbox.create();
this.emitter = new Emitter();
this.spawn = this.sandbox.stub(cp, 'spawn').callsFake(() => {
this.spawn = sandbox.stub(cp, 'spawn').callsFake(() => {
this.emitter = new Emitter();
this.emitter.kill = this.sandbox.stub();
this.emitter.kill = sandbox.stub();
this.emitter.stderr = new Emitter();
this.emitter.stdout = new Emitter();
return this.emitter;
});

this.write = this.sandbox.stub(Writable.prototype, 'write');
this.execSync = this.sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices));
this.wmSet = this.sandbox.spy(WeakMap.prototype, 'set');
this.write = sandbox.stub(Writable.prototype, 'write');
this.execSync = sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices));
this.wmSet = sandbox.spy(WeakMap.prototype, 'set');
done();
},

tearDown(done) {
this.sandbox.restore();
sandbox.restore();
done();
},

Expand Down Expand Up @@ -49,7 +48,7 @@ exports['av.Microphone'] = {
test.expect(3);

this.execSync.restore();
this.execSync = this.sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices.replace('card 0:', 'card 1:')));
this.execSync = sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices.replace('card 0:', 'card 1:')));

new av.Microphone();

Expand Down Expand Up @@ -193,7 +192,7 @@ exports['av.Microphone'] = {
const state = this.wmSet.lastCall.args[1];

state.cs = {
pipe: this.sandbox.stub(),
pipe: sandbox.stub(),
};

mic.listen({
Expand All @@ -218,7 +217,7 @@ exports['av.Microphone'] = {
const state = this.wmSet.lastCall.args[1];

state.cs = {
pipe: this.sandbox.stub(),
pipe: sandbox.stub(),
};

mic.listen({
Expand All @@ -238,7 +237,7 @@ exports['av.Microphone'] = {

stop(test) {
test.expect(4);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const mic = new av.Microphone();
mic.listen();
test.equal(mic.isListening, true);
Expand All @@ -253,12 +252,12 @@ exports['av.Microphone'] = {

stopListenAndMonitor(test) {
test.expect(4);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const mic = new av.Microphone();
const state = this.wmSet.lastCall.args[1];

state.cs = {
pipe: this.sandbox.stub(),
pipe: sandbox.stub(),
};

mic.listen();
Expand All @@ -275,10 +274,10 @@ exports['av.Microphone'] = {

stopIsNotSpeaking(test) {
test.expect(1);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const mic = new av.Microphone();

this.sandbox.spy(mic, 'emit');
sandbox.spy(mic, 'emit');

mic.stop();
test.equal(mic.emit.callCount, 0);
Expand All @@ -287,7 +286,7 @@ exports['av.Microphone'] = {

stopTwice(test) {
test.expect(2);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const mic = new av.Microphone();
mic.listen();
mic.on('stop', () => {
Expand Down
27 changes: 13 additions & 14 deletions test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ require('../common/bootstrap');

exports['av.Player'] = {
setUp(done) {
this.sandbox = sinon.sandbox.create();
this.emitter = new Emitter();
this.emitter.kill = this.sandbox.stub();
this.emitter.kill = sandbox.stub();
this.emitter.stderr = new Emitter();
this.spawn = this.sandbox.stub(cp, 'spawn').callsFake(() => this.emitter);
this.execSync = this.sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices));
this.wmSet = this.sandbox.spy(WeakMap.prototype, 'set');
this.spawn = sandbox.stub(cp, 'spawn').callsFake(() => this.emitter);
this.execSync = sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices));
this.wmSet = sandbox.spy(WeakMap.prototype, 'set');
done();
},

tearDown(done) {
this.sandbox.restore();
sandbox.restore();
done();
},

Expand Down Expand Up @@ -44,7 +43,7 @@ exports['av.Player'] = {
test.expect(2);

this.execSync.restore();
this.execSync = this.sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices.replace('card 0:', 'card 1:')));
this.execSync = sandbox.stub(cp, 'execSync').callsFake(() => new Buffer(aplayListDevices.replace('card 0:', 'card 1:')));

new av.Player('foo.mp3');

Expand Down Expand Up @@ -96,7 +95,7 @@ exports['av.Player'] = {
playError(test) {
test.expect(2);

const consoleerror = this.sandbox.stub(console, 'error');
const consoleerror = sandbox.stub(console, 'error');
const player = new av.Player('foo.mp3');

player.play();
Expand All @@ -114,7 +113,7 @@ exports['av.Player'] = {

playPausePlay(test) {
test.expect(5);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const player = new av.Player('foo.mp3');

player.play();
Expand Down Expand Up @@ -147,7 +146,7 @@ exports['av.Player'] = {

timeupdate(test) {
test.expect(0);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const player = new av.Player('foo.mp3');
player.play();
player.on('timeupdate', test.done);
Expand All @@ -156,7 +155,7 @@ exports['av.Player'] = {

ended(test) {
test.expect(0);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const player = new av.Player('foo.mp3');
player.play();
player.on('ended', test.done);
Expand All @@ -165,7 +164,7 @@ exports['av.Player'] = {

stop(test) {
test.expect(2);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const player = new av.Player('foo.mp3');
player.play();
player.on('stop', () => {
Expand All @@ -187,7 +186,7 @@ exports['av.Player'] = {

pause(test) {
test.expect(4);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const player = new av.Player('foo.mp3');
player.play();
test.equal(player.isPlaying, true);
Expand All @@ -203,7 +202,7 @@ exports['av.Player'] = {

pauseTwice(test) {
test.expect(3);
this.clock = this.sandbox.useFakeTimers();
this.clock = sandbox.useFakeTimers();
const player = new av.Player('foo.mp3');
player.play();
player.pause();
Expand Down
Loading

0 comments on commit 8bf27f3

Please sign in to comment.