Skip to content

Commit

Permalink
packages/firmata.js: fix object exported by lib/com.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jan 7, 2019
1 parent 707b9a5 commit aae09f2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/firmata.js/lib/com.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let list = function() {
return Promise.resolve([]);
};

class SerialPort extends Emitter {
class Stub extends Emitter {
constructor(path/*, options, openCallback*/) {
super();
this.isOpen = true;
Expand All @@ -31,12 +31,13 @@ class SerialPort extends Emitter {
}

// This trash is necessary for stubbing with sinon.
SerialPort.list = list;
SerialPort.SerialPort = SerialPort;
Stub.list = list;
Stub.SerialPort = Stub;

let com;
let sp;
let stub = SerialPort;
let error;
let SerialPort;
let stub = Stub;

try {
/* istanbul ignore if */
Expand All @@ -47,14 +48,13 @@ try {
if (process.env.IS_TEST_MODE) {
com = stub;
} else {
sp = require("serialport");
com = {
SerialPort: sp,
list: sp.list,
};
SerialPort = require("serialport");
com = SerialPort;
}
}
} catch (err) {}
} catch (err) {
error = err;
}


/* istanbul ignore if */
Expand All @@ -63,7 +63,8 @@ if (com == null) {
com = stub;
} else {
console.log("It looks like serialport didn't compile properly. This is a common problem and its fix is well documented here https://github.com/voodootikigod/node-serialport#to-install");
console.log("The result of requiring the package is: ", sp);
console.log(`The result of requiring the package is: ${SerialPort}`);
console.log(error);
throw "Missing serialport dependency";
}
}
Expand Down

0 comments on commit aae09f2

Please sign in to comment.