node-serialport-bindings-cpp/test/mocks/linux-list.js
Francis Gulotta 4fc1404c8c [all] Unify the serialport.list output (#1266)
- [osx] remove the 0x from productID and locationId and vendorId
- [linux] remove the starting 0x from any values, small refactor
- [linux] Fixup output using the hex encoded fields
- [windows] Grab the serial number from the pnp id
- Isolate list functions to their own platform files (c++)
- Better ensure our serialports fields are present

closes #1220
2017-07-29 19:40:39 -04:00

33 lines
676 B
JavaScript

// Mocks fs.read for listLinux
'use strict';
const EventEmitter = require('events');
const proxyquire = require('proxyquire');
const Readable = require('stream').Readable;
let mockPorts;
proxyquire.noPreserveCache();
const listLinux = proxyquire('../../lib/bindings/linux-list', {
child_process: {
spawn() {
const event = new EventEmitter();
const stream = new Readable();
event.stdout = stream;
stream.push(mockPorts);
stream.push(null);
return event;
}
}
});
proxyquire.preserveCache();
listLinux.setPorts = (ports) => {
mockPorts = ports;
};
listLinux.reset = () => {
mockPorts = {};
};
module.exports = listLinux;