Skip to content

Commit

Permalink
coverage: improved across all relevant files, but still not 100%
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 Apr 28, 2017
1 parent 004f9a7 commit f0cbb8d
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 39 deletions.
10 changes: 9 additions & 1 deletion lib/camera.js
Expand Up @@ -26,7 +26,6 @@ const videoUrl = port => {
return `http://${ip.address()}:${port}/?action=stream`;
};


try {
cp.spawnSync('kill -9 $(pgrep "mjpg_streamer")');
} catch (error) {}
Expand All @@ -52,6 +51,7 @@ class Camera extends Stream {
stream: null,
};

/* istanbul ignore else */
if (typeof options === 'undefined') {
options = {};
}
Expand Down Expand Up @@ -91,6 +91,7 @@ class Camera extends Stream {
}

// No string url provided
/* istanbul ignore else */
if (!url) {
if (options.url && isValidRemoteStream(options.url)) {
url = options.url;
Expand Down Expand Up @@ -123,6 +124,7 @@ class Camera extends Stream {
]);
},
stop() {
/* istanbul ignore else */
if (state.process) {
state.process.kill('SIGTERM');
state.process = null;
Expand All @@ -133,6 +135,11 @@ class Camera extends Stream {
priv.set(this, state);

Object.defineProperties(this, {
dimensions: {
get() {
return dimensions;
}
},
frame: {
get() {
return state.frame;
Expand Down Expand Up @@ -209,6 +216,7 @@ class Camera extends Stream {
// }

write(chunk) {
/* istanbul ignore else */
if (chunk) {
this.emit('data', chunk);
this.emit('frame', chunk);
Expand Down
17 changes: 9 additions & 8 deletions lib/install.js
@@ -1,3 +1,4 @@
'use strict';
/*
All of the operations in this module are synchronous
because without them, the environment cannot support
Expand All @@ -19,14 +20,14 @@
| 24s !!!!!!!!!!!! | cp.spawnSync('opkg', ['install', binary]) |
*/
var cp = require('child_process');
const cp = require('child_process');

// TODO: this can only work if the Tessel is connected to the network...
// var os = require('os');
// var wlan0 = os.os.networkInterfaces().wlan0[0];
// const os = require('os');
// const wlan0 = os.os.networkInterfaces().wlan0[0];

var profile = '/etc/profile';
var installed = {
const profile = '/etc/profile';
const installed = {
aplay: true,
arecord: true,
espeak: false,
Expand All @@ -37,7 +38,7 @@ var installed = {
};

module.exports = function(binary) {
var env = `AV_INSTALLED_${binary.toUpperCase()}`;
const env = `AV_INSTALLED_${binary.toUpperCase()}`;

if (global.IS_TEST_ENV || process.arch !== 'mipsel') {
return true;
Expand All @@ -53,8 +54,8 @@ module.exports = function(binary) {
return true;
}

var which = cp.spawnSync('which', [binary]);
var install;
const which = cp.spawnSync('which', [binary]);
let install;

// According to `which`, this binary does not exist
if (which.status === 1) {
Expand Down
6 changes: 5 additions & 1 deletion lib/microphone.js
Expand Up @@ -64,6 +64,7 @@ class Microphone extends Emitter {
args = options;
} else {
// Don't need to check for null, since those are handled above
/* istanbul ignore else */
if (typeof options === 'object') {
// mic.listen({
// ...
Expand All @@ -73,6 +74,7 @@ class Microphone extends Emitter {
const value = options[key];
let option = '';

/* istanbul ignore else */
if (key.length === 1) {
// mic.listen({
// c: 1,
Expand Down Expand Up @@ -100,6 +102,7 @@ class Microphone extends Emitter {
args = defaults.slice();
}

/* istanbul ignore else */
if (state.arecord === null) {
state.isListening = true;
state.currentTime = 0;
Expand All @@ -115,14 +118,15 @@ class Microphone extends Emitter {
}, 100);

// Apply some reasonable defaults...
Object.keys(arecord.options).forEach(key => {
arecord.keys.forEach(key => {
if (!args.includes(key)) {
args.push(key, arecord.options[key]);
}
});

state.arecord = cp.spawn('arecord', args);

/* istanbul ignore if */
if (this.debug) {
state.arecord.stderr.on('data', data => {
const lines = data.toString().split('\n').filter(Boolean).map(line => line.trim());
Expand Down
14 changes: 13 additions & 1 deletion lib/player.js
Expand Up @@ -8,6 +8,11 @@ const path = require('path');
// Program Specific
const priv = new WeakMap();

try {
cp.spawnSync('kill -9 $(pgrep "madplay")');
} catch (error) {}


function toSeconds(time) {
if (typeof time === 'number') {
return time;
Expand All @@ -32,7 +37,7 @@ class Player extends Emitter {
constructor(filename) {
super();

if (filename && !filename.endsWith('.mp3')) {
if (typeof filename === 'string' && !filename.endsWith('.mp3')) {
filename = filename || '';
throw new Error(
`av.Player can only playback mp3.
Expand Down Expand Up @@ -97,6 +102,7 @@ class Player extends Emitter {
time = file;
}

/* istanbul ignore else */
if (typeof time !== 'undefined') {
if (!/^([0-9]+:){0,2}[0-9]+([.;][0-9]+)?$/.test(time)) {
throw new Error(
Expand Down Expand Up @@ -172,6 +178,7 @@ class Player extends Emitter {
time = state.pauseTime;
}

/* istanbul ignore else */
if (state.process === null) {

if (time !== null) {
Expand Down Expand Up @@ -206,6 +213,7 @@ class Player extends Emitter {

state.process.on('exit', (code, signal) => {
if (code !== null && signal === null) {
/* istanbul ignore else */
if (state.interval) {
clearInterval(state.interval);
}
Expand All @@ -229,9 +237,11 @@ class Player extends Emitter {
return this;
}
state.isPlaying = false;
/* istanbul ignore else */
if (state.interval) {
clearInterval(state.interval);
}
/* istanbul ignore else */
if (state.process) {
state.process.kill('SIGTERM');
state.process = null;
Expand All @@ -246,10 +256,12 @@ class Player extends Emitter {
return this;
}
state.isPlaying = false;
/* istanbul ignore else */
if (state.interval) {
clearInterval(state.interval);
}
state.pauseTime = state.currentTime;
/* istanbul ignore else */
if (state.process) {
state.process.kill('SIGTERM');
state.process = null;
Expand Down
2 changes: 1 addition & 1 deletion test/.jshintrc
Expand Up @@ -14,7 +14,7 @@
"node": true,
"strict": false,
"esnext": true,
"unused": true,
"unused": false,
"globals": {
"exports": true,
"Promise": true,
Expand Down

0 comments on commit f0cbb8d

Please sign in to comment.