Skip to content

Commit

Permalink
com: rename Mock => SerialPort to make it clear what purpose this ser…
Browse files Browse the repository at this point in the history
…ves.
  • Loading branch information
rwaldron committed Aug 24, 2018
1 parent 7949f3f commit 9be4f0e
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions lib/com.js
Expand Up @@ -2,35 +2,34 @@

const Emitter = require("events");

function Mock(path, options, openCallback) {
this.isOpen = true;
this.baudRate = 0;
this.path = path;
}

Mock.prototype = Object.create(Emitter.prototype, {
constructor: {
value: Mock
class SerialPort extends Emitter {
constructor(path, options, openCallback) {
super();
this.isOpen = true;
this.baudRate = 0;
this.path = path;
}
});

Mock.prototype.write = function (buffer) {
// Tests are written to work with arrays not buffers
// this shouldn't impact the data, just the container
// This also should be changed in future test rewrites
if (Buffer.isBuffer(buffer)) {
buffer = Array.from(buffer);
}
write(buffer) {
// Tests are written to work with arrays not buffers
// this shouldn't impact the data, just the container
// This also should be changed in future test rewrites
/* istanbul ignore else */
if (Buffer.isBuffer(buffer)) {
buffer = Array.from(buffer);
}

this.lastWrite = buffer;
this.emit("write", buffer);
};
this.lastWrite = buffer;
this.emit("write", buffer);
}
}

let com;
let sp;
let stub = {
SerialPort: Mock,
SerialPort,
list() {
/* istanbul ignore next */
return Promise.resolve([]);
},
};
Expand Down

0 comments on commit 9be4f0e

Please sign in to comment.