Initial test build framework for node-red-nodes

This commit is contained in:
dceejay
2015-03-24 19:42:32 +00:00
parent 903bbe505a
commit 24394c4b18
7 changed files with 148 additions and 58 deletions

31
test/helper.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* Copyright 2014 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var path = require('path');
//console.log("WAS",process.env.NODE_RED_HOME);
//console.log("WAS2",__dirname);
process.env.NODE_RED_HOME = process.env.NODE_RED_HOME || path.resolve(__dirname+"/../../node-red");
//console.log("HOME",process.env.NODE_RED_HOME);
//console.log("PATH",path.join(process.env.NODE_RED_HOME, 'test', 'nodes', 'helper.js'));
var helper = require(path.join(process.env.NODE_RED_HOME, 'test', 'nodes', 'helper.js'));
try {
helper.nock = helper.nock || require("nock");
} catch(er) {
helper.nock = null;
}
module.exports = helper;

View File

@@ -20,22 +20,26 @@ var sinon = require('sinon');
var should = require("should");
var proxyquire = require("proxyquire");
var EventEmitter = require('events').EventEmitter
var util = require('util');
var data = require("./data");
var path = require("path");
var helper = require('../../../test/helper.js');
// Mute "Starting/Stopping flows to stdout"
var util = require('util');
var flows = proxyquire('../../../.node-red/red/nodes/flows.js', {
util: {
log: function(msg) {
if(!/ing flows/.test(msg)) {
util.log(msg);
}
}
}
});
var helper = require('../../../.node-red/test/nodes/helper.js');
//var flows = proxyquire('../../../.node-red/red/nodes/flows.js', {
//var flows = proxyquire('../../../../../red/nodes/flows.js', {
//util: {
//log: function(msg) {
//if(!/ing flows/.test(msg)) {
//util.log(msg);
//}
//}
//}
//});
//var helper = require('../../../.node-red/test/nodes/helper.js');
//var helper = require('../../../../../test/nodes/helper.js');
var currentPB = null;
var pushbulletStub = function() {
@@ -91,7 +95,7 @@ var pushbulletNode = proxyquire("../../../social/pushbullet/57-pushbullet.js", {
});
describe('pushbullet node', function() {
beforeEach(function(done) {
currentPB = new pushbulletStub();
helper.startServer(done);
@@ -221,7 +225,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "note");
helper.getNode("n3").send({
@@ -236,7 +240,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title", chan: "mychannel"},
{id:"n3", type:"helper", wires: [["n2"]]}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "note");
helper.getNode("n3").send({
@@ -251,7 +255,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "note");
helper.getNode("n3").send({
@@ -267,7 +271,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet", config: "n1", pushtype: "link", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "push");
helper.getNode("n3").send({
@@ -285,7 +289,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet", config: "n1", pushtype: "", title: ""},
{id:"n3", type:"helper", wires: [["n2"]]}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "_msg_"}}, function() {
var func = sinon.spy(currentPB, "push");
helper.getNode("n3").send({
@@ -306,7 +310,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "note");
helper.getNode("n3").send({
@@ -322,7 +326,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "link", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "push");
helper.getNode("n3").send({
@@ -339,7 +343,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "list", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "list");
helper.getNode("n3").send({
@@ -357,7 +361,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "list", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "list");
helper.getNode("n3").send({
@@ -375,7 +379,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "address", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "address");
helper.getNode("n3").send({
@@ -391,7 +395,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "file", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "file");
var fn = path.join(__dirname, "data.js")
@@ -408,10 +412,10 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "file", title: "title"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "file");
var errfn = sinon.spy(helper.getNode("n2"), "error");
var errfn = sinon.spy(helper.getNode("n2"), "error");
helper.getNode("n3").send({
payload: "hello",
});
@@ -426,7 +430,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "push");
helper.getNode("n3").send({
@@ -443,7 +447,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
var func = sinon.spy(currentPB, "updatePush");
helper.getNode("n3").send({
@@ -464,7 +468,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "delete"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
var func = sinon.spy(currentPB, "deletePush");
helper.getNode("n3").send({
@@ -481,7 +485,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "dismissal"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
var func = sinon.spy(currentPB, "updatePush");
helper.getNode("n3").send({
@@ -498,7 +502,7 @@ describe('pushbullet node', function() {
{id:"n2", type:"pushbullet", config: "n1", pushtype: "updatelist"},
{id:"n3", type:"helper", wires: [["n2"]]}
];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
var func = sinon.spy(currentPB, "updatePush");
helper.getNode("n3").send({
@@ -517,7 +521,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
done();
@@ -530,7 +534,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
var func = sinon.spy(helper.getNode("n2"), 'status');
currentPB.streamEmitter.emit("connect");
@@ -545,7 +549,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "clip");
@@ -561,7 +565,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "mirror");
@@ -577,7 +581,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "dismissal");
@@ -593,7 +597,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
var err = sinon.spy(helper.getNode("n1"), "error");
currentPB.streamEmitter.emit("message", {type: "push", push: {type: "push", push: {type: "unknown", data: "test"}}});
@@ -607,7 +611,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "note");
@@ -626,7 +630,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "link");
@@ -645,7 +649,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "address");
@@ -664,7 +668,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "file");
@@ -683,7 +687,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "list");
@@ -702,7 +706,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "delete");
@@ -720,7 +724,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("pushtype", "dismissal");
@@ -740,7 +744,7 @@ describe('pushbullet node', function() {
var flow = [{id:"n1", type:"pushbullet-config"},
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
{id:"n3", type:"helper"}];
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2:{filters:['a', 'b']}}, function() {
var counter = sinon.spy();
helper.getNode("n3").on("input", function(msg) {
@@ -748,7 +752,7 @@ describe('pushbullet node', function() {
});
var func = sinon.stub(currentPB, "history");
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
var msg0 = getPushReply('link'); msg0.pushes[0].source_device_iden = 'a';
func.onCall(0).yields(false, msg0);
@@ -762,7 +766,7 @@ describe('pushbullet node', function() {
func.onCall(2).yields(false, msg2);
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
var msg3 = getPushReply('link');
var msg3 = getPushReply('link');
delete msg3.pushes[0].source_device_iden;
delete msg3.pushes[0].target_device_iden;
func.onCall(3).yields(false, msg3);

View File

@@ -17,11 +17,9 @@
var should = require("should");
var sinon = require('sinon');
var fs = require("fs");
var helper = require('../../../test/helper.js');
var exifNode = require("../../../utility/exif/94-exif.js");
var helper = require('../../../../node-red/test/nodes/helper.js');
describe('exif node', function() {
"use strict";
@@ -35,17 +33,16 @@ describe('exif node', function() {
});
it('extracts location data from Exif data of JPEG', function(done) {
var exif = require('exif');
var ExifImage = exif.ExifImage;
// the jpg file is a single black dot but it was originally a photo taken at IBM Hursley
var data = fs.readFileSync("./exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor
var data = fs.readFileSync("test/utility/exif/exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor
var eD;
new ExifImage({ image : data }, function (error, exifData) {
if(error) {
if (error) {
done(error);
} else {
eD = exifData;

View File

@@ -1,56 +0,0 @@
/**
* Copyright 2013, 2014 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
module.exports = function(grunt) {
"use strict";
// Project configuration.
grunt.initConfig({
simplemocha: {
options: {
globals: ['expect'],
timeout: 3000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'spec'
},
all: { src: ['./*_spec.js'] },
},
jshint: {
options: {
// http://www.jshint.com/docs/options/
"asi": true, // allow missing semicolons
"curly": true, // require braces
"eqnull": true, // ignore ==null
"forin": true, // require property filtering in "for in" loops
"immed": true, // require immediate functions to be wrapped in ( )
"nonbsp": true, // warn on unexpected whitespace breaking chars
//"strict": true, // commented out for now as it causes 100s of warnings, but want to get there eventually
"loopfunc": true, // allow functions to be defined in loops
"sub": true // don't warn that foo['bar'] should be written as foo.bar
},
all: {
src: ['../../../utility/exif/*.js']
},
}
});
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-lint-inline');
grunt.registerTask('default', ['jshint:all', 'simplemocha:all']);
};