node-serialport-bindings-cpp/test/mocks/list-linux.js
Francis Gulotta dcfe2ab4ee Switch up testing infrastructure (#881)
- npm test now runs everything but stress tests
 - TEST_PORT is optional but now requires an arduino, the travis provided OS X serial port wasn't worth it
 - do some improvements to coverage
 - Drop grunt for file size and complexity
 - Eslint has dropped 0.10

I don't think Istanbul can detect coverage on sandboxed modules like our mocked bindings. Moving to an isolated binding will improve this situation.

I also don't think coveralls is working on travis
2016-07-24 22:20:23 -04:00

65 lines
1.4 KiB
JavaScript

// Mocks fs.read for listLinux
'use strict';
var SandboxedModule = require('sandboxed-module');
var mockPorts = {};
var characterDevice = true;
var error = false;
var listLinux = SandboxedModule.require('../../lib/list-linux', {
requires: {
fs: {
readdir: function(path, cb) {
if (error) {
return process.nextTick(function() {
cb(new Error('bad'));
});
}
process.nextTick(function() {
cb(null, Object.keys(mockPorts));
});
},
stat: function(path, cb) {
process.nextTick(function() {
cb(null, { isCharacterDevice: function() { return characterDevice } });
});
}
},
path: {
// needed for testing on windows
join: function() {
return Array.prototype.join.call(arguments, '/');
}
},
child_process: {
exec: function(cmd, cb) {
var port = cmd.split(/\/dev\/(.*)\)/)[1];
process.nextTick(function() {
cb(null, mockPorts[port]);
});
}
}
}
});
listLinux.setCharacterDevice = function(isCharacterDevice) {
characterDevice = isCharacterDevice;
};
listLinux.setPorts = function(ports) {
mockPorts = ports;
};
listLinux.error = function(err) {
error = err;
};
listLinux.reset = function() {
error = false;
mockPorts = {};
characterDevice = true;
};
module.exports = listLinux;