Fix type checking in unit tests

This commit is contained in:
Nick O'Leary
2016-10-10 13:27:43 +01:00
parent eb1a597456
commit 42f7dc1947
28 changed files with 281 additions and 252 deletions

View File

@@ -60,11 +60,15 @@ describe('sentiment Node', function() {
var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.number;
msg.sentiment.score.should.be.above(10);
done();
try {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.above(10);
done();
} catch(err) {
done(err);
}
});
var testString = 'good, great, best, brilliant';
jn1.receive({payload:testString});
@@ -80,7 +84,7 @@ describe('sentiment Node', function() {
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.number;
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.below(-10);
done();
});
@@ -98,7 +102,7 @@ describe('sentiment Node', function() {
jn2.on("input", function(msg) {
msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.number;
msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.equal(20);
done();
});

View File

@@ -32,7 +32,7 @@ describe('catch Node', function() {
var n2 = helper.getNode("n2");
n1.should.have.property('name', 'catch');
n2.on("input", function(msg) {
msg.should.be.a.Error;
msg.should.be.a.Error();
msg.toString().should.equal("Error: big error");
done();
});

View File

@@ -69,7 +69,7 @@ describe('debug node', function() {
count++;
}, function() {
try {
helper.log().called.should.be.true;
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "debug";
});

View File

@@ -66,7 +66,7 @@ describe('exec node', function() {
n2.on("input", function(msg) {
//console.log(msg);
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.String();
msg.payload.should.equal("echo");
});
n3.on("input", function(msg) {
@@ -99,13 +99,13 @@ describe('exec node', function() {
n2.on("input", function(msg) {
//console.log(msg);
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.String();
msg.payload.should.equal("echo and more");
});
n3.on("input", function(msg) {
//console.log(msg);
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.String();
msg.payload.should.equal("ECHO AND MORE");
done();
child_process.exec.restore();
@@ -130,11 +130,15 @@ describe('exec node', function() {
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
//console.log("n2",msg);
msg.should.have.property("payload");
msg.payload.should.be.a.Buffer;
msg.payload.length.should.equal(4);
done();
child_process.exec.restore();
try {
msg.should.have.property("payload");
Buffer.isBuffer(msg.payload).should.be.true();
msg.payload.length.should.equal(4);
child_process.exec.restore();
done();
} catch(err) {
done(err);
}
});
n1.receive({});
});
@@ -183,10 +187,14 @@ describe('exec node', function() {
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
//console.log(msg);
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.equal("hello world\n");
done();
try {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("hello world\n");
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"hello world"});
});
@@ -204,7 +212,7 @@ describe('exec node', function() {
n2.on("input", function(msg) {
//console.log(msg);
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.String();
msg.payload.should.equal("12345 deg C\n");
done();
});
@@ -222,16 +230,20 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.Buffer;
msg.payload.length.should.equal(7);
done();
try {
msg.should.have.property("payload");
Buffer.isBuffer(msg.payload).should.be.true();
msg.payload.length.should.equal(7);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:new Buffer([0x01,0x02,0x03,0x88])});
});
});
it('should now work if passed multiple words to spawn command', function(done) {
it('should work if passed multiple words to spawn command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo this now works", addpay:false, append:"", useSpawn:true},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
helper.load(execNode, flow, function() {
@@ -241,14 +253,18 @@ describe('exec node', function() {
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.String();
msg.payload.should.equal("this now works\n");
});
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.equal(0);
done();
try {
msg.should.have.property("payload");
msg.payload.should.be.a.Number();
msg.payload.should.equal(0);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:null});
});
@@ -264,7 +280,7 @@ describe('exec node', function() {
var n4 = helper.getNode("n4");
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.Number;
msg.payload.should.be.a.Number();
msg.payload.should.be.below(0);
done();
});
@@ -282,12 +298,12 @@ describe('exec node', function() {
var n4 = helper.getNode("n4");
n3.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.String();
msg.payload.should.equal("mkdir: /foo/bar/doo: No such file or directory\n");
});
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.String;
msg.payload.should.be.a.Number();
msg.payload.should.equal(1);
done();
});

View File

@@ -165,7 +165,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1");
n1.receive({payload:"foo",topic: "bar"});
try {
helper.log().called.should.be.true;
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "function";
});
@@ -188,7 +188,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true;
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
@@ -210,7 +210,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true;
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
@@ -232,7 +232,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true;
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});

View File

@@ -294,7 +294,7 @@ describe('delay Node', function() {
}
}
}
foundAtLeastOneDrop.should.be.true;
foundAtLeastOneDrop.should.be.true();
done();
} catch (err) {
done(err);

View File

@@ -217,7 +217,7 @@ describe('change Node', function() {
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
(msg.payload === null).should.be.true;
(msg.payload === null).should.be.true();
done();
} catch(err) {
done(err);

View File

@@ -154,7 +154,7 @@ describe('JOIN node', function() {
n2.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.be.an.Array;
msg.payload.should.be.an.Array();
msg.payload[0].should.equal(1);
msg.payload[1].should.equal(true);
//msg.payload[2].a.should.equal(1);
@@ -274,7 +274,7 @@ describe('JOIN node', function() {
n2.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.be.an.Array;
msg.payload.should.be.an.Array();
msg.payload[0].should.equal(1);
msg.payload[1].should.equal(2);
msg.payload[2].should.equal(3);
@@ -323,8 +323,8 @@ describe('JOIN node', function() {
n2.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.be.an.Array;
(msg.payload[0] === undefined).should.be.true;
msg.payload.should.be.an.Array();
(msg.payload[0] === undefined).should.be.true();
msg.payload[1].should.equal(2);
msg.payload[2].should.equal(3);
msg.payload[3].should.equal(4);
@@ -347,7 +347,7 @@ describe('JOIN node', function() {
n2.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.be.an.Array;
msg.payload.should.be.an.String();
msg.payload.should.equal("abcd");
done();
}

View File

@@ -32,7 +32,7 @@ describe('html node', function() {
});
beforeEach(function() {
fs.existsSync(file).should.be.true;
fs.existsSync(file).should.be.true();
});
afterEach(function() {
@@ -170,7 +170,7 @@ describe('html node', function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.receive({payload:null,topic: "bar"});
helper.log().called.should.be.true;
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "html";
});

View File

@@ -156,7 +156,7 @@ describe('tail Node', function() {
msg.should.have.property('topic', fileToTail);
inputCounter++;
if (inputCounter === 1) {
warned.should.be.false;
warned.should.be.false();
msg.payload.should.equal("Tail message line append");
} else if (inputCounter === 2) {
msg.payload.should.equal("Tail message line truncate");
@@ -166,7 +166,7 @@ describe('tail Node', function() {
if (inputCounter === 5) {
setTimeout(function() {
warned.should.be.true;
warned.should.be.true();
done();
},100);
}