mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
Use the jshintrc file for grunt and cleanup some issues.
This commit is contained in:
parent
4493647b08
commit
87d3fa08a7
9 changed files with 88 additions and 226 deletions
145
.jshintrc
145
.jshintrc
|
|
@ -1,155 +1,28 @@
|
|||
{
|
||||
// Whether the scan should stop on first error.
|
||||
"passfail": false,
|
||||
// Maximum errors before stopping.
|
||||
"maxerr": 100,
|
||||
|
||||
|
||||
// Predefined globals
|
||||
|
||||
// Whether the standard browser globals should be predefined.
|
||||
"browser": false,
|
||||
// Whether the Node.js environment globals should be predefined.
|
||||
"node": true,
|
||||
// Whether the Rhino environment globals should be predefined.
|
||||
"rhino": false,
|
||||
// Whether CouchDB globals should be predefined.
|
||||
"couch": false,
|
||||
// Whether the Windows Scripting Host environment globals should be predefined.
|
||||
"wsh": false,
|
||||
|
||||
// Whether jQuery globals should be predefined.
|
||||
"jquery": false,
|
||||
// Whether Prototype and Scriptaculous globals should be predefined.
|
||||
"prototypejs": false,
|
||||
// Whether MooTools globals should be predefined.
|
||||
"mootools": false,
|
||||
// Whether Dojo Toolkit globals should be predefined.
|
||||
"dojo": false,
|
||||
|
||||
// Custom predefined globals.
|
||||
"predef": [],
|
||||
|
||||
// Development
|
||||
|
||||
// Whether debugger statements should be allowed.
|
||||
"debug": false,
|
||||
// Whether logging globals should be predefined (console, alert, etc.).
|
||||
"devel": false,
|
||||
|
||||
|
||||
// ECMAScript 5
|
||||
|
||||
// Whether the "use strict"; pragma should be required.
|
||||
"strict": true,
|
||||
// Whether global "use strict"; should be allowed (also enables strict).
|
||||
"globalstrict": true,
|
||||
"mocha": true,
|
||||
|
||||
|
||||
// The Good Parts
|
||||
|
||||
// Whether automatic semicolon insertion should be allowed.
|
||||
"asi": false,
|
||||
// Whether line breaks should not be checked, e.g. `return [\n] x`.
|
||||
"laxbreak": false,
|
||||
// Whether bitwise operators (&, |, ^, etc.) should be forbidden.
|
||||
"bitwise": false,
|
||||
// Whether assignments inside `if`, `for` and `while` should be allowed. Usually
|
||||
// conditions and loops are for comparison, not assignments.
|
||||
"boss": true,
|
||||
// Whether curly braces around all blocks should be required.
|
||||
"curly": true,
|
||||
// Whether `===` and `!==` should be required (instead of `==` and `!=`).
|
||||
"eqeqeq": true,
|
||||
// Whether `== null` comparisons should be allowed, even if `eqeqeq` is `true`.
|
||||
"eqnull": false,
|
||||
// Whether `eval` should be allowed.
|
||||
"evil": false,
|
||||
// Whether ExpressionStatement should be allowed as Programs.
|
||||
"expr": true,
|
||||
// Whether `for in` loops must filter with `hasOwnPrototype`.
|
||||
"forin": false,
|
||||
// Whether immediate invocations must be wrapped in parens, e.g.
|
||||
// `( function(){}() );`.
|
||||
"immed": true,
|
||||
// Whether use before define should be forbidden.
|
||||
"latedef": false,
|
||||
// Whether functions should be allowed to be defined within loops.
|
||||
"latedef": true,
|
||||
"loopfunc": false,
|
||||
// Whether arguments.caller and arguments.callee should be forbidden.
|
||||
"noarg": false,
|
||||
// Whether `.` should be forbidden in regexp literals.
|
||||
"regexp": false,
|
||||
// Whether unescaped first/last dash (-) inside brackets in regexps should be allowed.
|
||||
"regexdash": false,
|
||||
// Whether script-targeted URLs should be allowed.
|
||||
"scripturl": false,
|
||||
// Whether variable shadowing should be allowed.
|
||||
"noarg": true,
|
||||
"shadow": false,
|
||||
// Whether `new function () { ... };` and `new Object;` should be allowed.
|
||||
"supernew": false,
|
||||
// Whether variables must be declared before used.
|
||||
"undef": true,
|
||||
// Whether `this` inside a non-constructor function should be allowed.
|
||||
"validthis": false,
|
||||
// Whether smarttabs should be allowed
|
||||
// (http://www.emacswiki.org/emacs/SmartTabs).
|
||||
"smarttabs": true,
|
||||
// Whether the `__proto__` property should be allowed.
|
||||
"proto": false,
|
||||
// Whether one-case switch statements should be allowed.
|
||||
"onecase": false,
|
||||
// Whether non-standard (but widely adopted) globals should be predefined.
|
||||
"nonstandard": false,
|
||||
// Allow multiline strings.
|
||||
"multistr": false,
|
||||
// Whether line breaks should not be checked around commas.
|
||||
"laxcomma": false,
|
||||
// Whether semicolons may be ommitted for the trailing statements inside of a
|
||||
// one-line blocks.
|
||||
"lastsemic": false,
|
||||
// Whether the `__iterator__` property should be allowed.
|
||||
"iterator": false,
|
||||
// Whether only function scope should be used for scope tests.
|
||||
"funcscope": false,
|
||||
// Whether es.next specific syntax should be allowed.
|
||||
"esnext": false,
|
||||
|
||||
|
||||
// Style preferences
|
||||
|
||||
// Whether constructor names must be capitalized.
|
||||
"newcap": false,
|
||||
// Whether empty blocks should be forbidden.
|
||||
"noempty": false,
|
||||
// Whether using `new` for side-effects should be forbidden.
|
||||
"nonew": false,
|
||||
// Whether names should be checked for leading or trailing underscores
|
||||
// (object._attribute would be forbidden).
|
||||
"nomen": false,
|
||||
// Whether only one var statement per function should be allowed.
|
||||
"onevar": false,
|
||||
// Whether increment and decrement (`++` and `--`) should be forbidden.
|
||||
"plusplus": false,
|
||||
// Whether all forms of subscript notation are allowed.
|
||||
"sub": false,
|
||||
// Whether trailing whitespace rules apply.
|
||||
"trailing": false,
|
||||
// Specify indentation.
|
||||
"newcap": true,
|
||||
"noempty": true,
|
||||
"nonew": true,
|
||||
"indent": 2,
|
||||
// Whether strict whitespace rules apply.
|
||||
"white": false,
|
||||
// Quote formatting
|
||||
"white": true,
|
||||
"quotmark": true,
|
||||
|
||||
// Complexity
|
||||
|
||||
// Maximum number of function parameters.
|
||||
"maxparams": 5,
|
||||
// Maximum block nesting depth.
|
||||
"maxdepth": 3,
|
||||
// Maximum number of statements per function.
|
||||
"maxstatements": 25,
|
||||
// Maximum cyclomatic complexity.
|
||||
"maxcomplexity": 6
|
||||
"maxstatements": 54, //default 25
|
||||
"maxcomplexity": 30 //default 6
|
||||
}
|
||||
|
|
|
|||
17
Gruntfile.js
17
Gruntfile.js
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function(grunt) {
|
||||
|
||||
grunt.initConfig({
|
||||
|
|
@ -9,17 +11,8 @@ module.exports = function(grunt) {
|
|||
},
|
||||
jshint: {
|
||||
all: ['*.js', 'test/**/*.js', 'arduinoTest/**/*.js'],
|
||||
options: {
|
||||
node: true,
|
||||
'-W030': true, // to allow mocha expects syntax
|
||||
globals: {
|
||||
before: false,
|
||||
after: false,
|
||||
beforeEach: false,
|
||||
afterEach: false,
|
||||
describe: false,
|
||||
it: false
|
||||
}
|
||||
options:{
|
||||
jshintrc: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -28,4 +21,4 @@ module.exports = function(grunt) {
|
|||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.registerTask('default', ['jshint', 'mochaTest']);
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
/*jslint node: true */
|
||||
/*global describe, it */
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var util = require('util');
|
||||
var serialPort = require('../serialport');
|
||||
|
||||
describe ('requiresComPort', function() {
|
||||
|
||||
|
||||
describe('echo hello', function() {
|
||||
it('sends hello to the last port and validates that it is received back (see arduinoEcho.ino for echo sketch)', function(done) {
|
||||
serialPort.list(function(err, ports) {
|
||||
|
|
@ -16,7 +14,7 @@ describe ('requiresComPort', function() {
|
|||
chai.assert.isDefined(ports, 'ports is not defined');
|
||||
chai.assert.isTrue(ports.length > 0, 'no ports found');
|
||||
|
||||
var data = new Buffer("hello");
|
||||
var data = new Buffer('hello');
|
||||
|
||||
var port = new serialPort.SerialPort(ports.slice(-1)[0].comName, null, false);
|
||||
port.on('error', function(err) {
|
||||
|
|
@ -71,7 +69,7 @@ describe ('requiresComPort', function() {
|
|||
chai.assert.isDefined(ports, 'ports is not defined');
|
||||
chai.assert.isTrue(ports.length > 0, 'no ports found');
|
||||
|
||||
var data = new Buffer("hello");
|
||||
var data = new Buffer('hello');
|
||||
|
||||
var port = new serialPort.SerialPort(ports.slice(-1)[0].comName, null, false);
|
||||
port.on('error', function(err) {
|
||||
|
|
@ -117,4 +115,4 @@ describe ('requiresComPort', function() {
|
|||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*jslint node: true */
|
||||
/*global describe, it */
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var util = require('util');
|
||||
|
|
@ -36,7 +36,7 @@ describe ('stress', function() {
|
|||
chai.assert.isDefined(ports, 'ports is not defined');
|
||||
chai.assert.isTrue(ports.length > 0, 'no ports found');
|
||||
|
||||
var data = new Buffer("hello");
|
||||
var data = new Buffer('hello');
|
||||
|
||||
var port = new serialPort.SerialPort(ports.slice(-1)[0].comName, null, false);
|
||||
port.on('error', function(err) {
|
||||
|
|
@ -55,7 +55,7 @@ describe ('stress', function() {
|
|||
}, 20 );
|
||||
|
||||
setTimeout(function() {
|
||||
|
||||
|
||||
clearInterval(intervalId);
|
||||
|
||||
var diff = hd.end();
|
||||
|
|
@ -71,4 +71,4 @@ describe ('stress', function() {
|
|||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
10
parsers.js
10
parsers.js
|
|
@ -1,20 +1,20 @@
|
|||
/*jslint node: true */
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
// Copyright 2011 Chris Williams <chris@iterativedesigns.com>
|
||||
|
||||
module.exports = {
|
||||
raw: function (emitter, buffer) {
|
||||
emitter.emit("data", buffer);
|
||||
emitter.emit('data', buffer);
|
||||
},
|
||||
|
||||
//encoding: ascii utf8 utf16le ucs2 base64 binary hex
|
||||
//More: http://nodejs.org/api/buffer.html#buffer_buffer
|
||||
readline: function (delimiter, encoding) {
|
||||
if (typeof delimiter === "undefined" || delimiter === null) { delimiter = "\r"; }
|
||||
if (typeof encoding === "undefined" || encoding === null) { encoding = "utf8"; }
|
||||
if (typeof delimiter === 'undefined' || delimiter === null) { delimiter = '\r'; }
|
||||
if (typeof encoding === 'undefined' || encoding === null) { encoding = 'utf8'; }
|
||||
// Delimiter buffer saved in closure
|
||||
var data = "";
|
||||
var data = '';
|
||||
return function (emitter, buffer) {
|
||||
// Collect data
|
||||
data += buffer.toString(encoding);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
/*jslint node: true */
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
// Copyright 2011 Chris Williams <chris@iterativedesigns.com>
|
||||
|
||||
|
|
@ -33,8 +32,8 @@ function SerialPortFactory() {
|
|||
var DATABITS = [5, 6, 7, 8];
|
||||
var STOPBITS = [1, 1.5, 2];
|
||||
var PARITY = ['none', 'even', 'mark', 'odd', 'space'];
|
||||
var FLOWCONTROLS = ["XON", "XOFF", "XANY", "RTSCTS"];
|
||||
var SETS = ["rts", "cts", "dtr", "dts"];
|
||||
var FLOWCONTROLS = ['XON', 'XOFF', 'XANY', 'RTSCTS'];
|
||||
var SETS = ['rts', 'cts', 'dtr', 'dts'];
|
||||
|
||||
|
||||
// Stuff from ReadStream, refactored for our usage:
|
||||
|
|
@ -143,7 +142,7 @@ function SerialPortFactory() {
|
|||
var fcup = flowControl.toUpperCase();
|
||||
var idx = FLOWCONTROLS.indexOf(fcup);
|
||||
if (idx < 0) {
|
||||
var err = new Error('Invalid "flowControl": ' + fcup + ". Valid options: " + FLOWCONTROLS.join(", "));
|
||||
var err = new Error('Invalid "flowControl": ' + fcup + '. Valid options: ' + FLOWCONTROLS.join(', '));
|
||||
callback(err);
|
||||
return;
|
||||
} else {
|
||||
|
|
@ -173,9 +172,9 @@ function SerialPortFactory() {
|
|||
return;
|
||||
}
|
||||
if (!err) {
|
||||
err = new Error("Disconnected");
|
||||
err = new Error('Disconnected');
|
||||
}
|
||||
self.emit("disconnect", err);
|
||||
self.emit('disconnect', err);
|
||||
};
|
||||
|
||||
if (process.platform !== 'win32') {
|
||||
|
|
@ -210,7 +209,6 @@ function SerialPortFactory() {
|
|||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
// console.log("open");
|
||||
self.emit('error', err);
|
||||
}
|
||||
return;
|
||||
|
|
@ -240,7 +238,7 @@ function SerialPortFactory() {
|
|||
SerialPort.prototype.write = function (buffer, callback) {
|
||||
var self = this;
|
||||
if (!this.fd) {
|
||||
var err = new Error("Serialport not open.");
|
||||
var err = new Error('Serialport not open.');
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
|
|
@ -299,7 +297,7 @@ function SerialPortFactory() {
|
|||
if (self.fd >= 0) {
|
||||
self.serialPoller.start();
|
||||
}
|
||||
} else if (err.code && (err.code === "EBADF" || err.code === 'ENXIO' || (err.errno === -1 || err.code === 'UNKNOWN'))) { // handle edge case were mac/unix doesn't clearly know the error.
|
||||
} else if (err.code && (err.code === 'EBADF' || err.code === 'ENXIO' || (err.errno === -1 || err.code === 'UNKNOWN'))) { // handle edge case were mac/unix doesn't clearly know the error.
|
||||
self.disconnected(err);
|
||||
} else {
|
||||
self.fd = null;
|
||||
|
|
@ -384,12 +382,12 @@ function SerialPortFactory() {
|
|||
if (self.options.disconnectedCallback) {
|
||||
self.options.disconnectedCallback(err);
|
||||
} else {
|
||||
self.emit("disconnect", err);
|
||||
self.emit('disconnect', err);
|
||||
}
|
||||
self.paused = true;
|
||||
self.closing = true;
|
||||
|
||||
self.emit("close");
|
||||
self.emit('close');
|
||||
|
||||
// clean up all other items
|
||||
fd = self.fd;
|
||||
|
|
@ -427,7 +425,7 @@ function SerialPortFactory() {
|
|||
return;
|
||||
}
|
||||
if (!fd) {
|
||||
var err = new Error("Serialport not open.");
|
||||
var err = new Error('Serialport not open.');
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
|
|
@ -484,29 +482,29 @@ function SerialPortFactory() {
|
|||
var lines = output.split('\n');
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
if (line !== "") {
|
||||
var line_parts = lines[i].split("=");
|
||||
if (line !== '') {
|
||||
var line_parts = lines[i].split('=');
|
||||
result[line_parts[0].trim()] = line_parts[1].trim();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
var as_json = udev_output_to_json(udev_output);
|
||||
var pnpId = as_json.DEVLINKS.split(" ")[0];
|
||||
pnpId = pnpId.substring(pnpId.lastIndexOf("/") + 1);
|
||||
var pnpId = as_json.DEVLINKS.split(' ')[0];
|
||||
pnpId = pnpId.substring(pnpId.lastIndexOf('/') + 1);
|
||||
var port = {
|
||||
comName: as_json.DEVNAME,
|
||||
manufacturer: as_json.ID_VENDOR,
|
||||
serialNumber: as_json.ID_SERIAL,
|
||||
pnpId: pnpId,
|
||||
vendorId: "0x" + as_json.ID_VENDOR_ID,
|
||||
productId: "0x" + as_json.ID_MODEL_ID
|
||||
vendorId: '0x' + as_json.ID_VENDOR_ID,
|
||||
productId: '0x' + as_json.ID_MODEL_ID
|
||||
};
|
||||
|
||||
callback(null, port);
|
||||
}
|
||||
|
||||
fs.readdir("/dev/serial/by-id", function (err, files) {
|
||||
fs.readdir('/dev/serial/by-id', function (err, files) {
|
||||
if (err) {
|
||||
// if this directory is not found this could just be because it's not plugged in
|
||||
if (err.errno === 34) {
|
||||
|
|
@ -521,7 +519,7 @@ function SerialPortFactory() {
|
|||
return;
|
||||
}
|
||||
|
||||
var dirName = "/dev/serial/by-id";
|
||||
var dirName = '/dev/serial/by-id';
|
||||
async.map(files, function (file, callback) {
|
||||
var fileName = path.join(dirName, file);
|
||||
fs.readlink(fileName, function (err, link) {
|
||||
|
|
@ -557,7 +555,7 @@ function SerialPortFactory() {
|
|||
var fd = self.fd;
|
||||
|
||||
if (!fd) {
|
||||
var err = new Error("Serialport not open.");
|
||||
var err = new Error('Serialport not open.');
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
|
|
@ -594,7 +592,7 @@ function SerialPortFactory() {
|
|||
options.dts = options.dts || options.dts || _options.dts;
|
||||
|
||||
if (!fd) {
|
||||
var err = new Error("Serialport not open.");
|
||||
var err = new Error('Serialport not open.');
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
|
|
@ -621,7 +619,7 @@ function SerialPortFactory() {
|
|||
var fd = this.fd;
|
||||
|
||||
if (!fd) {
|
||||
var err = new Error("Serialport not open.");
|
||||
var err = new Error('Serialport not open.');
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
|
|
@ -661,4 +659,4 @@ function SerialPortFactory() {
|
|||
|
||||
util.inherits(SerialPortFactory, EventEmitter);
|
||||
|
||||
module.exports = new SerialPortFactory();
|
||||
module.exports = new SerialPortFactory();
|
||||
|
|
|
|||
|
|
@ -1,47 +1,47 @@
|
|||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var expect = chai.expect;
|
||||
var sinonChai = require("sinon-chai");
|
||||
var sinon = require("sinon");
|
||||
var sinonChai = require('sinon-chai');
|
||||
var sinon = require('sinon');
|
||||
chai.use(sinonChai);
|
||||
|
||||
var parsers = require('../parsers');
|
||||
|
||||
describe("parsers", function () {
|
||||
describe('parsers', function () {
|
||||
|
||||
describe("#raw", function () {
|
||||
it("emits data exactly as it's written", function () {
|
||||
var data = new Buffer("BOGUS");
|
||||
describe('#raw', function () {
|
||||
it('emits data exactly as it\'s written', function () {
|
||||
var data = new Buffer('BOGUS');
|
||||
var spy = sinon.spy();
|
||||
parsers.raw({ emit: spy }, data);
|
||||
expect(spy.getCall(0).args[1]).to.deep.equal(new Buffer("BOGUS"));
|
||||
expect(spy.getCall(0).args[1]).to.deep.equal(new Buffer('BOGUS'));
|
||||
});
|
||||
});
|
||||
|
||||
describe("#readline", function () {
|
||||
it("emits data events split on a delimiter", function () {
|
||||
var data = new Buffer("I love robots\rEach and Every One\r");
|
||||
describe('#readline', function () {
|
||||
it('emits data events split on a delimiter', function () {
|
||||
var data = new Buffer('I love robots\rEach and Every One\r');
|
||||
var spy = sinon.spy();
|
||||
var parser = parsers.readline();
|
||||
parser({ emit: spy }, data);
|
||||
expect(spy).to.have.been.calledWith("data", "I love robots");
|
||||
expect(spy).to.have.been.calledWith("data", "Each and Every One");
|
||||
expect(spy).to.have.been.calledWith('data', 'I love robots');
|
||||
expect(spy).to.have.been.calledWith('data', 'Each and Every One');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#byteLength', function(){
|
||||
it("emits data events every 8 bytes", function () {
|
||||
var data = new Buffer("Robots are so freaking cool!");
|
||||
it('emits data events every 8 bytes', function () {
|
||||
var data = new Buffer('Robots are so freaking cool!');
|
||||
var spy = sinon.spy();
|
||||
var parser = parsers.byteLength(8);
|
||||
parser({ emit: spy }, data);
|
||||
expect(spy.callCount).to.equal(3);
|
||||
expect(spy.getCall(0).args[1].length).to.equal(8);
|
||||
expect(spy.getCall(0).args[1]).to.deep.equal(new Buffer("Robots a"));
|
||||
expect(spy.getCall(1).args[1]).to.deep.equal(new Buffer("re so fr"));
|
||||
expect(spy.getCall(2).args[1]).to.deep.equal(new Buffer("eaking c"));
|
||||
expect(spy.getCall(0).args[1]).to.deep.equal(new Buffer('Robots a'));
|
||||
expect(spy.getCall(1).args[1]).to.deep.equal(new Buffer('re so fr'));
|
||||
expect(spy.getCall(2).args[1]).to.deep.equal(new Buffer('eaking c'));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sinon = require("sinon");
|
||||
var sinon = require('sinon');
|
||||
var chai = require('chai');
|
||||
var expect = chai.expect;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ describe('SerialPort', function () {
|
|||
});
|
||||
|
||||
describe('Constructor', function () {
|
||||
it("opens the port immediately", function (done) {
|
||||
it('opens the port immediately', function (done) {
|
||||
var port = new SerialPort('/dev/exists', function (err) {
|
||||
expect(err).to.not.be.ok;
|
||||
done();
|
||||
|
|
@ -41,7 +41,7 @@ describe('SerialPort', function () {
|
|||
it('emits an error on the factory when erroring without a callback', function (done) {
|
||||
// finish the test on error
|
||||
MockedSerialPort.once('error', function (err) {
|
||||
chai.assert.isDefined(err, "didn't get an error");
|
||||
chai.assert.isDefined(err, 'didn\'t get an error');
|
||||
done();
|
||||
});
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ describe('SerialPort', function () {
|
|||
describe('reading data', function () {
|
||||
|
||||
it('emits data events by default', function (done) {
|
||||
var testData = new Buffer("I am a really short string");
|
||||
var testData = new Buffer('I am a really short string');
|
||||
var port = new SerialPort('/dev/exists', function () {
|
||||
port.once('data', function(recvData) {
|
||||
expect(recvData).to.eql(testData);
|
||||
|
|
@ -89,7 +89,7 @@ describe('SerialPort', function () {
|
|||
});
|
||||
|
||||
it('calls the dataCallback if set', function (done) {
|
||||
var testData = new Buffer("I am a really short string");
|
||||
var testData = new Buffer('I am a really short string');
|
||||
var opt = {
|
||||
dataCallback: function (recvData) {
|
||||
expect(recvData).to.eql(testData);
|
||||
|
|
@ -123,8 +123,8 @@ describe('SerialPort', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it("emits data after being reopened", function (done) {
|
||||
var data = new Buffer("Howdy!");
|
||||
it('emits data after being reopened', function (done) {
|
||||
var data = new Buffer('Howdy!');
|
||||
var port = new SerialPort('/dev/exists', function () {
|
||||
port.close();
|
||||
port.open(function () {
|
||||
|
|
@ -140,7 +140,7 @@ describe('SerialPort', function () {
|
|||
});
|
||||
|
||||
describe('close', function () {
|
||||
it("fires a close event when it's closed", function (done) {
|
||||
it('fires a close event when it\'s closed', function (done) {
|
||||
var port = new SerialPort('/dev/exists', function () {
|
||||
var closeSpy = sandbox.spy();
|
||||
port.on('close', closeSpy);
|
||||
|
|
@ -150,7 +150,7 @@ describe('SerialPort', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it("fires a close event after being reopened", function (done) {
|
||||
it('fires a close event after being reopened', function (done) {
|
||||
var port = new SerialPort('/dev/exists', function () {
|
||||
var closeSpy = sandbox.spy();
|
||||
port.on('close', closeSpy);
|
||||
|
|
@ -164,7 +164,7 @@ describe('SerialPort', function () {
|
|||
});
|
||||
|
||||
describe('disconnect', function () {
|
||||
it("fires a disconnect event", function (done) {
|
||||
it('fires a disconnect event', function (done) {
|
||||
var port = new SerialPort('/dev/exists', {
|
||||
disconnectedCallback: function (err) {
|
||||
expect(err).to.not.be.ok;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sinon = require("sinon");
|
||||
var sinon = require('sinon');
|
||||
var chai = require('chai');
|
||||
var expect = chai.expect;
|
||||
|
||||
|
|
@ -17,19 +17,19 @@ describe('SerialPort', function () {
|
|||
|
||||
|
||||
describe('Initialization', function () {
|
||||
if (process.version.indexOf("v0.11.") ===0) {
|
||||
it("does not currently work due to an issue with node unstable release, works in master.", function (done) {
|
||||
if (process.version.indexOf('v0.11.') ===0) {
|
||||
it('does not currently work due to an issue with node unstable release, works in master.', function (done) {
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
it("Throws an error in callback when trying to open an invalid port", function (done) {
|
||||
it('Throws an error in callback when trying to open an invalid port', function (done) {
|
||||
var SerialPort = require('../').SerialPort;
|
||||
var port = new SerialPort('/dev/nullbad', function (err) {
|
||||
chai.assert.isDefined(err, "didn't get an error");
|
||||
chai.assert.isDefined(err, 'didn\'t get an error');
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue