diff --git a/lib/com.js b/lib/com.js index b83da7f..bc82a96 100644 --- a/lib/com.js +++ b/lib/com.js @@ -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([]); }, };