Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable node/no-missing-require */
// Load Serialport with mock bindings
// const SerialPort = require('../test'); // from inside the serialport repo
const SerialPort = require('serialport/test') // when installed as a package
const MockBinding = SerialPort.Binding
const portPath = 'COM_ANYTHING'
// The mock bindings can pretend to be an arduino with the `arduinoEcho` program loaded.
// This will echo any byte written to the port and will emit "READY" data after opening.
// You enable this by passing `echo: true`
// Another additional option is `record`, if `record: true` is present all
// writes will be recorded into a single buffer for the lifetime of the port
// it can be read from `port.binding.recording`.
// Create a port
MockBinding.createPort(portPath, { echo: false, record: false })
const port = new SerialPort(portPath)
port.on('open', () => {
'use strict';
var Insteon = require('../').Insteon;
var should = require('should');
var SerialPort = require('serialport/test');
var MockBinding = SerialPort.Binding;
MockBinding.createPort('/dev/home-controller-mock', { echo: false, record: true, readyData: '' });
var mockSerial = require('../lib/Test/mockSerial');
var Plan = require('../lib/Test/Plan');
describe('Insteon Gateway (Serial Interface)', function () {
this.timeout(5000);
it('tests serial connection #1', function (done) {
var gw = new Insteon();
gw.SerialPort = SerialPort;
gw.serial('/dev/home-controller-mock', {}, function () {
gw.close();
gw.serial('/dev/home-controller-mock', { baudRate: 19200, dataBits: 8, parity: 'none', stopBits: 1 }, function () {
gw.close();