Skip to content

Commit 4565108

Browse files
committed
Merge pull request #21 from hindessm/add-simple-tests
Add test code using NODE_RED_HOME to find node-red tree.
2 parents 4794b0d + d4bb938 commit 4565108

File tree

9 files changed

+187
-6
lines changed

9 files changed

+187
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
.npm
3+
coverage

Gruntfile.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright 2013, 2014 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
module.exports = function(grunt) {
18+
19+
// Project configuration.
20+
grunt.initConfig({
21+
pkg: grunt.file.readJSON('package.json'),
22+
simplemocha: {
23+
options: {
24+
globals: ['expect'],
25+
timeout: 3000,
26+
ignoreLeaks: false,
27+
ui: 'bdd',
28+
reporter: 'spec'
29+
},
30+
all: { src: ['test/*/*_spec.js'] },
31+
},
32+
jshint: {
33+
options: {
34+
// http://www.jshint.com/docs/options/
35+
"asi": true, // allow missing semicolons
36+
"curly": true, // require braces
37+
"eqnull": true, // ignore ==null
38+
"forin": true, // require property filtering in "for in" loops
39+
"immed": true, // require immediate functions to be wrapped in ( )
40+
"nonbsp": true, // warn on unexpected whitespace breaking chars
41+
//"strict": true, // commented out for now as it causes 100s of warnings, but want to get there eventually
42+
"loopfunc": true, // allow functions to be defined in loops
43+
"sub": true // don't warn that foo['bar'] should be written as foo.bar
44+
},
45+
all: [
46+
'*/*.js'
47+
],
48+
},
49+
inlinelint: {
50+
html: ['*/*.html']
51+
}
52+
});
53+
54+
grunt.loadNpmTasks('grunt-simple-mocha');
55+
grunt.loadNpmTasks('grunt-contrib-jshint');
56+
grunt.loadNpmTasks('grunt-lint-inline');
57+
58+
grunt.registerTask('default',
59+
['jshint:all', 'inlinelint:html', 'simplemocha:all']);
60+
61+
};

dropbox/dropbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ module.exports = function(RED) {
3535
this.filename = n.filename || "";
3636
this.localFilename = n.localFilename || "";
3737
this.dropboxConfig = RED.nodes.getNode(n.dropbox);
38-
var credentials = this.dropboxConfig.credentials;
38+
var credentials = this.dropboxConfig ? this.dropboxConfig.credentials : {};
3939
var node = this;
40-
if (credentials && credentials.appkey && credentials.appsecret &&
40+
if (credentials.appkey && credentials.appsecret &&
4141
credentials.accesstoken) {
4242
var dropbox = new Dropbox.Client({
4343
//uid: credentials.uid,

flickr/flickr.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
var v1 = $("#node-config-input-client_key").val();
7272
var v2 = $("#node-config-input-client_secret").val();
7373

74-
$("#node-config-start-auth").toggleClass("disabled",(v1.length == 0 || v2.length == 0));
74+
$("#node-config-start-auth").toggleClass("disabled",(v1.length === 0 || v2.length === 0));
7575

7676
}
7777
$("#node-config-input-client_key").on('change keydown paste input',updateFlickrAuthButton);
@@ -93,7 +93,7 @@
9393
} else {
9494
window.flickrConfigNodeIntervalId = window.setTimeout(pollFlickrCredentials,2000);
9595
}
96-
})
96+
});
9797
}
9898

9999
updateFlickrAuthButton();
@@ -121,7 +121,7 @@
121121
$("#node-config-start-auth").click(function(e) {
122122
var key = $("#node-config-input-client_key").val();
123123
var secret = $("#node-config-input-client_secret").val();
124-
if (key == "" || secret == "") {
124+
if (key === "" || secret === "") {
125125
e.preventDefault();
126126
}
127127
});

flickr/flickr.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ module.exports = function(RED) {
124124
});
125125
var form = r.form();
126126
for (var p in signedUrlOptions.query) {
127-
form.append(p,signedUrlOptions.query[p]);
127+
if (signedUrlOptions.query.hasOwnProperty(p)) {
128+
form.append(p,signedUrlOptions.query[p]);
129+
}
128130
}
129131
form.append('photo',msg.payload,{filename:"image_upload"});
130132
}

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@
2323
"dropbox": "dropbox/dropbox.js"
2424
}
2525
}
26+
},
27+
"devDependencies": {
28+
"grunt": "0.4.5",
29+
"grunt-cli": "0.1.13",
30+
"grunt-lint-inline": "0.4.3",
31+
"grunt-simple-mocha": "0.4.0",
32+
"grunt-contrib-jshint": "0.10.0",
33+
"mocha": "1.21.4",
34+
"should": "4.0.4"
35+
}
2636
}

test/dropbox/dropbox_spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2014 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var should = require("should");
18+
var dropboxNode = require("../../dropbox/dropbox.js");
19+
var helper = require('../helper.js');
20+
21+
describe('dropbox nodes', function() {
22+
23+
before(function(done) {
24+
helper.startServer(done);
25+
});
26+
27+
afterEach(function() {
28+
helper.unload();
29+
});
30+
31+
describe('out node', function() {
32+
it('can be loaded', function(done) {
33+
helper.load(dropboxNode,
34+
[{id:"n1", type:"helper", wires:[["n2"]]},
35+
{id:"n2", type:"dropbox out"}], function() {
36+
var n1 = helper.getNode("n1");
37+
n1.should.have.property('id', 'n1');
38+
done();
39+
});
40+
});
41+
});
42+
});

test/flickr/flickr_spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2014 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var should = require("should");
18+
var flickrNode = require("../../flickr/flickr.js");
19+
var helper = require('../helper.js');
20+
21+
describe('flickr nodes', function() {
22+
23+
before(function(done) {
24+
helper.startServer(done);
25+
});
26+
27+
afterEach(function() {
28+
helper.unload();
29+
});
30+
31+
describe('out node', function() {
32+
it('can be loaded', function(done) {
33+
helper.load(flickrNode,
34+
[{id:"n1", type:"helper", wires:[["n2"]]},
35+
{id:"n2", type:"flickr out"}], function() {
36+
var n1 = helper.getNode("n1");
37+
n1.should.have.property('id', 'n1');
38+
done();
39+
});
40+
});
41+
});
42+
});

test/helper.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2014 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var path = require('path');
18+
19+
process.env.NODE_RED_HOME = process.env.NODE_RED_HOME || path.resolve(__dirname+"/../../node-red");
20+
21+
var helper = require(path.join(process.env.NODE_RED_HOME,
22+
'test', 'nodes', 'helper.js'));
23+
module.exports = helper;

0 commit comments

Comments
 (0)