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
This commit is contained in:
Francis Gulotta 2016-07-24 22:20:23 -04:00 • committed by GitHub
parent a9e7fe889b
commit dcfe2ab4ee
17 changed files with 74 additions and 84 deletions

View file

@ -12,7 +12,7 @@ module.exports = {
"curly": 2,
"eqeqeq": 2,
"max-depth": 2,
"max-statements": [2, 34],
"max-statements": [2, 36],
"new-cap": 2,
"no-caller": 2,
"no-cond-assign": 2,

2
.gitignore vendored
View file

@ -7,4 +7,4 @@ npm-debug.log
gyp-mac-tool
.node_pre_gyprc
/.idea
.nyc_output
coverage

2
.istanbul.yml Normal file
View file

@ -0,0 +1,2 @@
instrumentation:
root: lib

View file

@ -21,4 +21,4 @@ npm-debug.log
gyp-mac-tool
.node_pre_gyprc
/.idea
.nyc_output
coverage

View file

@ -71,16 +71,13 @@ before_install:
- if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi;
- echo "Publishing native platform Binary Package? ->" $PUBLISH_BINARY
# Set a test serialport for integration testing when we run our tests if we have one
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then export TEST_PORT='/dev/cu.serial1'; fi
install:
# ensure source install works
- npm install --build-from-source
script:
# test our module
- npm run lint
# linting no longer works on node 0.10
- node bin/at-least-node-4.0.js && npm run lint || true
- node ./
- npm test
@ -95,4 +92,4 @@ script:
- if [[ $PUBLISH_BINARY == true ]]; then npm install --fallback-to-build=false; fi;
after_success:
- npm run coverage
- npm run report-coverage

View file

@ -1,27 +0,0 @@
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
mochaTest: {
test: {
options: { reporter: 'spec' },
src: ['test/*.js']
}
},
eslint: {
src: [
'*.js',
'lib/**/*.js',
'test/**/*.js',
'bin/**/*.js',
'examples/**/*.js'
]
}
});
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('gruntify-eslint');
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('default', ['lint', 'test']);
};

View file

@ -69,7 +69,13 @@ build_script:
- npm install --build-from-source --msvs_version=2013
test_script:
- npm run lint
- ps: >
if (node bin/at-least-node-4.0.js) {
npm run lint;
} else {
"Not linting because the linter doesn't run on this version of node" | Write-Host
}
true;
- node ./
- npm test
- IF %PUBLISH_BINARY% == 1 (node-pre-gyp package 2>&1)
@ -78,7 +84,9 @@ test_script:
- IF %PUBLISH_BINARY% == 1 (npm install --fallback-to-build=false)
on_success:
- npm run coverage
- npm run report-coverage
deploy: OFF
matrix:
fast_finish: true

5
bin/at-least-node-4.0.js Normal file
View file

@ -0,0 +1,5 @@
'use strict';
if (process.versions.node.split('.')[0] < 4) {
process.exit(1);
}

View file

@ -1,17 +1,10 @@
'use strict';
var bindings = require('bindings')('serialport.node');
var listUnix = require('./list-unix');
var listLinux = require('./list-linux');
var linux = process.platform !== 'win32' && process.platform !== 'darwin';
function listLinux(callback) {
callback = callback || function(err) {
if (err) { this.emit('error', err) }
}.bind(this);
return listUnix(callback);
};
var platformOptions = {};
if (process.platform !== 'win32') {
platformOptions = {

View file

@ -92,7 +92,7 @@ function lookupPort(file) {
return execAsync(udevadm).then(udevParser);
}
function listUnix(callback) {
function listLinux(callback) {
var dirName = '/dev';
readdirAsync(dirName)
.catch(function(err) {
@ -109,4 +109,4 @@ function listUnix(callback) {
.then(function(data) { callback(null, data) }, function(err) { callback(err) });
}
module.exports = listUnix;
module.exports = listLinux;

View file

@ -75,6 +75,10 @@ function correctOptions(options) {
}
function SerialPort(path, options, callback) {
if (!(this instanceof SerialPort)) {
return new SerialPort(path, options, callback);
}
if (typeof callback === 'boolean') {
throw new TypeError('`openImmediately` is now called `autoOpen` and is a property of options');
}

View file

@ -64,15 +64,13 @@
"chai": "^3.5.0",
"chai-subset": "^1.2.2",
"coveralls": "^2.11.9",
"eslint": "^3.1.1",
"eslint-config-standard": "^5.1.0",
"eslint-plugin-promise": "^1.1.0",
"eslint-plugin-standard": "^1.3.2",
"grunt": "^1.0.0",
"grunt-mocha-test": "^0.12.7",
"gruntify-eslint": "^2.0.0",
"istanbul": "^0.4.4",
"mocha": "^2.4.5",
"node-pre-gyp-github": "^1.1.2",
"nyc": "^6.4.4",
"sandboxed-module": "^2.0.3",
"sinon": "^1.17.3"
},
@ -90,13 +88,10 @@
"scripts": {
"install": "node-pre-gyp install --fallback-to-build",
"rebuild-all": "npm rebuild && node-gyp rebuild",
"gyp-rebuild": "node-gyp rebuild",
"stress": "mocha --no-timeouts test/arduinoTest/stress.js",
"integration": "mocha test/arduinoTest/integration.js test/integration-lite.js",
"grunt": "grunt",
"lint": "grunt --verbose lint",
"test": "nyc grunt --verbose test",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint *.js lib/**/*.js test/**/*.js bin/**/*.js examples/**/*.js",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha test/*.js test/arduinoTest/integration.js test/integration-lite.js",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"valgrind": "valgrind --leak-check=full --show-possibly-lost=no node --expose-gc --trace-gc node_modules/.bin/grunt test"
},
"gypfile": true

View file

@ -17,11 +17,12 @@ switch (process.platform) {
var testPort = process.env.TEST_PORT;
if (!testPort) {
throw 'These test require an arduino loaded with the arduinoEcho program on a serialport set to the TEST_PORT env var';
}
describe('SerialPort Integration Tests', function() {
if (!testPort) {
it('Requires an Arduino loaded with the arduinoEcho program on a serialport set to the TEST_PORT env var');
return;
}
describe('SerialPort Integration tests', function() {
it('.list', function(done) {
SerialPort.list(function(err, ports) {
var foundPort = false;

View file

@ -1,7 +1,7 @@
'use strict';
var assert = require('chai').assert;
var listUnix = require('./mocks/list-unix');
var listLinux = require('./mocks/list-linux');
var ports = {
'ttyS0':
@ -86,14 +86,14 @@ var portOutput = [
}
];
describe('listUnix', function() {
describe('listLinux', function() {
beforeEach(function() {
listUnix.reset();
listLinux.reset();
});
it('lists available serialports', function(done) {
listUnix.setPorts(ports);
listUnix(function(err, ports) {
listLinux.setPorts(ports);
listLinux(function(err, ports) {
assert.isNull(err);
assert.deepEqual(ports, portOutput);
done();
@ -101,9 +101,9 @@ describe('listUnix', function() {
});
it('does not list non character devices', function(done) {
listUnix.setCharacterDevice(false);
listUnix.setPorts(ports);
listUnix(function(err, ports) {
listLinux.setCharacterDevice(false);
listLinux.setPorts(ports);
listLinux(function(err, ports) {
assert.isNull(err);
assert.deepEqual(ports, []);
done();
@ -111,8 +111,8 @@ describe('listUnix', function() {
});
it('returns an error to callback', function(done) {
listUnix.error(true);
listUnix(function(err) {
listLinux.error(true);
listLinux(function(err) {
assert.instanceOf(err, Error);
done();
});

View file

@ -192,7 +192,7 @@ var hardware = new Hardware();
var SandboxedModule = require('sandboxed-module');
var serialPort = SandboxedModule.require('../../', {
var SerialPort = SandboxedModule.require('../../', {
requires: {
fs: {
read: hardware.fakeRead.bind(hardware)
@ -208,6 +208,6 @@ var serialPort = SandboxedModule.require('../../', {
}
});
serialPort.hardware = hardware;
SerialPort.hardware = hardware;
module.exports = serialPort;
module.exports = SerialPort;

View file

@ -1,4 +1,4 @@
// Mocks fs.read for listUnix
// Mocks fs.read for listLinux
'use strict';
@ -8,7 +8,7 @@ var mockPorts = {};
var characterDevice = true;
var error = false;
var listUnix = SandboxedModule.require('../../lib/list-unix', {
var listLinux = SandboxedModule.require('../../lib/list-linux', {
requires: {
fs: {
readdir: function(path, cb) {
@ -44,22 +44,22 @@ var listUnix = SandboxedModule.require('../../lib/list-unix', {
}
});
listUnix.setCharacterDevice = function(isCharacterDevice) {
listLinux.setCharacterDevice = function(isCharacterDevice) {
characterDevice = isCharacterDevice;
};
listUnix.setPorts = function(ports) {
listLinux.setPorts = function(ports) {
mockPorts = ports;
};
listUnix.error = function(err) {
listLinux.error = function(err) {
error = err;
};
listUnix.reset = function() {
listLinux.reset = function() {
error = false;
mockPorts = {};
characterDevice = true;
};
module.exports = listUnix;
module.exports = listLinux;

View file

@ -37,9 +37,21 @@ describe('SerialPort', function() {
done();
}
});
it('takes lowercase options', function(done) {
var port = new SerialPort.SerialPort('/dev/exists', { baudrate: 14400, autoOpen: false });
assert.equal(port.options.baudRate, 14400);
done();
});
});
describe('Constructor', function() {
it('provides auto construction', function(done) {
var serialPort = SerialPort;
this.port = serialPort('/dev/exists', done);
});
describe('autoOpen', function() {
it('opens the port automatically', function(done) {
this.port = new SerialPort('/dev/exists', function(err) {
@ -161,7 +173,7 @@ describe('SerialPort', function() {
});
});
describe('Functions', function() {
describe('Methods', function() {
describe('#open', function() {
it('passes the port to the bindings', function(done) {
var openSpy = sandbox.spy(bindings, 'open');