2014-05-03 23:26:35 +02:00
/ * *
* 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 .
* * /
2013-10-20 22:42:01 +02:00
var should = require ( "should" ) ;
2014-08-01 23:05:49 +02:00
var sinon = require ( "sinon" ) ;
2014-08-04 12:27:26 +02:00
var path = require ( "path" ) ;
2014-09-23 18:09:23 +02:00
var when = require ( "when" ) ;
2013-10-20 22:42:01 +02:00
2014-08-01 23:05:49 +02:00
var RedNodes = require ( "../../../red/nodes" ) ;
2014-07-17 09:06:30 +02:00
var RedNode = require ( "../../../red/nodes/Node" ) ;
2014-08-01 23:05:49 +02:00
var typeRegistry = require ( "../../../red/nodes/registry" ) ;
var events = require ( "../../../red/events" ) ;
afterEach ( function ( ) {
typeRegistry . clear ( ) ;
} ) ;
2013-10-20 22:42:01 +02:00
2015-03-22 23:54:52 +01:00
describe ( 'red/nodes/registry' , function ( ) {
2014-11-13 16:03:33 +01:00
2014-08-04 12:27:26 +02:00
var resourcesDir = _ _dirname + path . sep + "resources" + path . sep ;
2014-11-13 16:03:33 +01:00
2015-03-22 23:54:52 +01:00
function stubSettings ( s , available , initialConfig ) {
2014-11-20 13:15:09 +01:00
s . available = function ( ) { return available ; } ;
s . set = function ( s , v ) { return when . resolve ( ) ; } ;
2015-03-22 23:54:52 +01:00
s . get = function ( s ) { return initialConfig ; } ;
2014-11-20 13:15:09 +01:00
return s ;
2014-08-28 01:35:07 +02:00
}
2015-03-22 23:54:52 +01:00
var settings = stubSettings ( { } , false , null ) ;
var settingsWithStorage = stubSettings ( { } , true , null ) ;
2015-03-30 22:49:20 +02:00
var settingsWithStorageAndInitialConfig = stubSettings ( { } , true , { "node-red" : { module : "testModule" , name : "testName" , version : "testVersion" , nodes : { "node" : { id : "node-red/testName" , name : "test" , types : [ "a" , "b" ] , enabled : true } } } } ) ;
2015-03-22 23:54:52 +01:00
it ( 'loads initial config' , function ( done ) {
typeRegistry . init ( settingsWithStorageAndInitialConfig ) ;
2015-03-30 22:49:20 +02:00
typeRegistry . getNodeList ( ) . should . have . lengthOf ( 1 ) ;
2015-03-22 23:54:52 +01:00
done ( ) ;
} ) ;
2015-03-30 22:49:20 +02:00
it ( 'migrates legacy format' , function ( done ) {
var settings = {
available : function ( ) { return true ; } ,
set : sinon . stub ( ) . returns ( when . resolve ( ) ) ,
get : function ( ) { return {
"123" : {
"name" : "72-sentiment.js" ,
"types" : [
"sentiment"
] ,
"enabled" : true
} ,
"456" : {
"name" : "20-inject.js" ,
"types" : [
"inject"
] ,
"enabled" : true
} ,
"789" : {
"name" : "testModule:a-module.js" ,
"types" : [
"example"
] ,
"enabled" : true ,
"module" : "testModule"
}
} }
} ;
var expected = JSON . parse ( '{"node-red":{"name":"node-red","nodes":{"sentiment":{"name":"sentiment","types":["sentiment"],"enabled":true,"module":"node-red"},"inject":{"name":"inject","types":["inject"],"enabled":true,"module":"node-red"}}},"testModule":{"name":"testModule","nodes":{"a-module.js":{"name":"a-module.js","types":["example"],"enabled":true,"module":"testModule"}}}}' ) ;
typeRegistry . init ( settings ) ;
settings . set . calledOnce . should . be . true ;
settings . set . args [ 0 ] [ 1 ] . should . eql ( expected ) ;
done ( ) ;
} ) ;
2014-08-01 23:05:49 +02:00
it ( 'handles nodes that export a function' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 12:27:26 +02:00
typeRegistry . load ( resourcesDir + "TestNode1" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode1" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
var nodeConstructor = typeRegistry . get ( "test-node-1" ) ;
2014-08-04 18:12:54 +02:00
nodeConstructor . should . be . type ( "function" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'handles nodes that export a function returning a resolving promise' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 12:27:26 +02:00
typeRegistry . load ( resourcesDir + "TestNode2" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode2" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode2" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-2" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
var nodeConstructor = typeRegistry . get ( "test-node-2" ) ;
2014-08-04 18:12:54 +02:00
nodeConstructor . should . be . type ( "function" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'handles nodes that export a function returning a rejecting promise' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 12:27:26 +02:00
typeRegistry . load ( resourcesDir + "TestNode3" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode3" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode3" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-3" ] ) ;
2014-08-28 01:35:07 +02:00
list [ 0 ] . should . have . property ( "enabled" , true ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "err" , "fail" ) ;
2014-07-30 19:07:20 +02:00
2014-08-01 23:05:49 +02:00
var nodeConstructor = typeRegistry . get ( "test-node-3" ) ;
2014-08-04 18:12:54 +02:00
( nodeConstructor === null ) . should . be . true ;
2014-11-13 16:03:33 +01:00
2014-07-30 19:07:20 +02:00
done ( ) ;
2014-08-01 23:05:49 +02:00
} ) . catch ( function ( e ) {
done ( e ) ;
2014-07-30 19:07:20 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-07-30 19:07:20 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'handles files containing multiple nodes' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 12:27:26 +02:00
typeRegistry . load ( resourcesDir + "MultipleNodes1" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/MultipleNodes1" ) ;
list [ 0 ] . should . have . property ( "name" , "MultipleNodes1" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-multiple-1a" , "test-node-multiple-1b" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
var nodeConstructor = typeRegistry . get ( "test-node-multiple-1a" ) ;
2014-08-04 18:12:54 +02:00
nodeConstructor . should . be . type ( "function" ) ;
2014-07-30 19:07:20 +02:00
2014-08-01 23:05:49 +02:00
nodeConstructor = typeRegistry . get ( "test-node-multiple-1b" ) ;
2014-08-04 18:12:54 +02:00
nodeConstructor . should . be . type ( "function" ) ;
2014-11-13 16:03:33 +01:00
2014-07-30 19:07:20 +02:00
done ( ) ;
2014-08-01 23:05:49 +02:00
} ) . catch ( function ( e ) {
done ( e ) ;
2014-07-30 19:07:20 +02:00
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'handles nested directories' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 12:27:26 +02:00
typeRegistry . load ( resourcesDir + "NestedDirectoryNode" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/NestedNode" ) ;
list [ 0 ] . should . have . property ( "name" , "NestedNode" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "nested-node-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'emits type-registered and node-icon-dir events' , function ( done ) {
var eventEmitSpy = sinon . spy ( events , "emit" ) ;
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 12:27:26 +02:00
typeRegistry . load ( resourcesDir + "NestedDirectoryNode" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/NestedNode" ) ;
list [ 0 ] . should . have . property ( "name" , "NestedNode" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "nested-node-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:19:33 +02:00
eventEmitSpy . callCount . should . equal ( 2 ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
eventEmitSpy . firstCall . args [ 0 ] . should . be . equal ( "node-icon-dir" ) ;
2014-08-04 12:27:26 +02:00
eventEmitSpy . firstCall . args [ 1 ] . should . be . equal (
resourcesDir + "NestedDirectoryNode" + path . sep + "NestedNode" + path . sep + "icons" ) ;
2014-07-30 19:07:20 +02:00
2014-08-01 23:05:49 +02:00
eventEmitSpy . secondCall . args [ 0 ] . should . be . equal ( "type-registered" ) ;
eventEmitSpy . secondCall . args [ 1 ] . should . be . equal ( "nested-node-1" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
eventEmitSpy . restore ( ) ;
} ) ;
2014-07-30 19:07:20 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2015-03-22 23:54:52 +01:00
it ( 'rejects a duplicate node type registration during load' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( stubSettings ( {
2014-08-04 12:27:26 +02:00
nodesDir : [ resourcesDir + "TestNode1" , resourcesDir + "DuplicateTestNode" ]
2014-08-28 01:35:07 +02:00
} , false ) ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
2014-11-13 16:03:33 +01:00
2014-11-20 13:15:09 +01:00
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode1" ) ;
2014-08-01 23:05:49 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
2014-07-30 19:07:20 +02:00
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2015-03-22 23:54:52 +01:00
it ( 'rejects a duplicate node type registration' , function ( done ) {
typeRegistry . init ( stubSettings ( {
nodesDir : [ resourcesDir + "TestNode1" ]
} , false ) ) ;
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
/*jshint immed: false */
( function ( ) {
typeRegistry . registerType ( "test-node-1" , { } ) ;
} ) . should . throw ( ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-08-01 23:05:49 +02:00
it ( 'handles nodesDir as a string' , function ( done ) {
2014-07-30 19:07:20 +02:00
2014-08-28 01:35:07 +02:00
typeRegistry . init ( stubSettings ( {
nodesDir : resourcesDir + "TestNode1"
} , false ) ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list [ 0 ] . should . have . property ( "types" , [ "test-node-1" ] ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( "Loading of non-existing nodesDir should succeed" ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'handles invalid nodesDir' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( stubSettings ( {
nodesDir : "wontexist"
} , false ) ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . be . empty ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( "Loading of non-existing nodesDir should succeed" ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2015-01-10 23:09:37 +01:00
it ( 'returns nothing for an unregistered type config' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var config = typeRegistry . getNodeConfig ( "imaginary-shark" ) ;
( config === null ) . should . be . true ;
2015-01-10 23:09:37 +01:00
done ( ) ;
2014-08-01 23:05:49 +02:00
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'excludes node files listed in nodesExcludes' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( stubSettings ( {
2014-08-01 23:05:49 +02:00
nodesExcludes : [ "TestNode1.js" ] ,
2014-08-04 12:27:26 +02:00
nodesDir : [ resourcesDir + "TestNode1" , resourcesDir + "TestNode2" ]
2014-08-28 01:35:07 +02:00
} , false ) ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list [ 0 ] . should . have . property ( "types" , [ "test-node-2" ] ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
it ( 'returns the node configurations' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( stubSettings ( {
2014-08-04 12:27:26 +02:00
nodesDir : [ resourcesDir + "TestNode1" , resourcesDir + "TestNode2" ]
2014-08-28 01:35:07 +02:00
} , false ) ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-01 23:05:49 +02:00
var list = typeRegistry . getNodeList ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
var nodeConfigs = typeRegistry . getNodeConfigs ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
// TODO: this is brittle...
2014-08-18 15:28:54 +02:00
nodeConfigs . should . equal ( "<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n<script type=\"text/x-red\" data-template-name=\"test-node-2\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-2\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-2',{});</script>\n<style></style>\n" ) ;
2014-11-13 16:03:33 +01:00
2014-08-01 23:05:49 +02:00
var nodeId = list [ 0 ] . id ;
var nodeConfig = typeRegistry . getNodeConfig ( nodeId ) ;
2014-08-28 01:35:07 +02:00
nodeConfig . should . equal ( "<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n" ) ;
2014-08-01 23:05:49 +02:00
done ( ) ;
2014-07-30 19:07:20 +02:00
} ) . catch ( function ( e ) {
2014-08-01 23:05:49 +02:00
done ( e ) ;
2014-07-30 19:07:20 +02:00
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
it ( 'stores the node list' , function ( done ) {
var settings = {
nodesDir : [ resourcesDir + "TestNode1" , resourcesDir + "TestNode2" , resourcesDir + "TestNode3" ] ,
available : function ( ) { return true ; } ,
2014-11-26 16:25:15 +01:00
set : function ( s , v ) { return when . resolve ( ) ; } ,
get : function ( s ) { return null ; }
} ;
2014-08-28 01:35:07 +02:00
var settingsSave = sinon . spy ( settings , "set" ) ;
typeRegistry . init ( settings ) ;
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-11-26 16:25:15 +01:00
var nodeList = typeRegistry . getNodeList ( ) ;
var moduleList = typeRegistry . getModuleList ( ) ;
nodeList . should . be . Array . and . have . length ( 3 ) ;
moduleList . should . be . Array . and . have . length ( 1 ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
settingsSave . callCount . should . equal ( 1 ) ;
2014-12-08 11:10:16 +01:00
settingsSave . firstCall . args [ 0 ] . should . be . equal ( "nodes" ) ;
2014-08-28 01:35:07 +02:00
var savedList = settingsSave . firstCall . args [ 1 ] ;
2014-11-13 16:03:33 +01:00
2014-11-26 16:25:15 +01:00
savedList [ moduleList [ 0 ] . name ] . name . should . equal ( moduleList [ 0 ] . name ) ;
2014-11-13 16:03:33 +01:00
2014-11-26 16:25:15 +01:00
savedList [ moduleList [ 0 ] . name ] . nodes [ moduleList [ 0 ] . nodes [ 0 ] . name ] . name . should . equal ( moduleList [ 0 ] . nodes [ 0 ] . name ) ;
savedList [ moduleList [ 0 ] . name ] . nodes [ moduleList [ 0 ] . nodes [ 1 ] . name ] . name . should . equal ( moduleList [ 0 ] . nodes [ 1 ] . name ) ;
savedList [ moduleList [ 0 ] . name ] . nodes [ moduleList [ 0 ] . nodes [ 2 ] . name ] . name . should . equal ( moduleList [ 0 ] . nodes [ 2 ] . name ) ;
savedList [ moduleList [ 0 ] . name ] . nodes [ moduleList [ 0 ] . nodes [ 0 ] . name ] . should . not . have . property ( "err" ) ;
savedList [ moduleList [ 0 ] . name ] . nodes [ moduleList [ 0 ] . nodes [ 1 ] . name ] . should . not . have . property ( "err" ) ;
savedList [ moduleList [ 0 ] . name ] . nodes [ moduleList [ 0 ] . nodes [ 2 ] . name ] . should . not . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
settingsSave . restore ( ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
it ( 'returns node info by type or id' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-04 18:12:54 +02:00
typeRegistry . load ( resourcesDir + "TestNode1" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-13 16:03:33 +01:00
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode1" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-04 18:12:54 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2015-03-22 23:54:52 +01:00
2015-03-30 22:49:20 +02:00
var id = "node-red/TestNode1" ;
var type = "test-node-1" ;
2014-11-13 16:03:33 +01:00
2015-03-22 23:54:52 +01:00
2014-08-04 18:12:54 +02:00
var info = typeRegistry . getNodeInfo ( id ) ;
2015-03-30 22:49:20 +02:00
info . should . have . property ( "loaded" ) ;
delete info . loaded ;
2014-08-04 18:12:54 +02:00
list [ 0 ] . should . eql ( info ) ;
var info2 = typeRegistry . getNodeInfo ( type ) ;
2015-03-30 22:49:20 +02:00
info2 . should . have . property ( "loaded" ) ;
delete info2 . loaded ;
2014-08-04 18:12:54 +02:00
list [ 0 ] . should . eql ( info2 ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
2014-11-13 16:03:33 +01:00
} ) ;
2015-03-22 23:54:52 +01:00
it ( 'returns null node info for unrecognised id' , function ( done ) {
typeRegistry . init ( settings ) ;
typeRegistry . load ( resourcesDir + "TestNode1" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
should . not . exist ( typeRegistry . getNodeInfo ( "does-not-exist" ) ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-11-21 12:31:07 +01:00
it ( 'returns modules list' , function ( done ) {
2014-11-13 16:03:33 +01:00
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
typeRegistry . init ( settingsWithStorage ) ;
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
typeRegistry . addModule ( "TestNodeModule" ) . then ( function ( ) {
2014-11-20 16:17:13 +01:00
var list = typeRegistry . getModuleList ( ) ;
2014-11-13 16:03:33 +01:00
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list [ 0 ] . should . have . property ( "name" , "TestNodeModule" ) ;
list [ 0 ] . should . have . property ( "nodes" ) ;
list [ 0 ] . nodes . should . be . an . Array . and . have . lengthOf ( 2 ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
} ) ;
} ) ;
2014-11-21 12:31:07 +01:00
it ( 'returns module info' , function ( done ) {
2014-11-13 16:03:33 +01:00
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
typeRegistry . init ( settingsWithStorage ) ;
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2015-03-30 22:49:20 +02:00
typeRegistry . addModule ( "TestNodeModule" ) . then ( function ( modInfo ) {
var info = typeRegistry . getModuleInfo ( "TestNodeModule" ) ;
2015-03-22 23:54:52 +01:00
2015-03-30 22:49:20 +02:00
modInfo . should . eql ( info ) ;
2015-03-22 23:54:52 +01:00
should . not . exist ( typeRegistry . getModuleInfo ( "does-not-exist" ) ) ;
2014-11-13 16:03:33 +01:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
} ) ;
2014-08-04 18:12:54 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-03 22:17:24 +02:00
it ( 'scans the node_modules path for node files' , function ( done ) {
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
2014-11-13 16:03:33 +01:00
2014-08-03 22:17:24 +02:00
var eventEmitSpy = sinon . spy ( events , "emit" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
2014-08-04 12:27:26 +02:00
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
2014-08-03 22:17:24 +02:00
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
2014-08-04 12:27:26 +02:00
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
2014-08-03 22:17:24 +02:00
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-03 22:17:24 +02:00
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
2014-08-04 12:27:26 +02:00
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
2014-08-03 22:17:24 +02:00
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settings ) ;
2014-08-03 22:17:24 +02:00
typeRegistry . load ( "wontexist" , false ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
2014-08-04 18:12:54 +02:00
list . should . be . an . Array . and . have . lengthOf ( 2 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "TestNodeModule/TestNodeMod1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNodeMod1" ) ;
list [ 0 ] . should . have . property ( "module" , "TestNodeModule" ) ;
2014-08-03 22:17:24 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-mod-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2014-08-04 18:12:54 +02:00
2014-11-20 13:15:09 +01:00
list [ 1 ] . should . have . property ( "id" , "TestNodeModule/TestNodeMod2" ) ;
list [ 1 ] . should . have . property ( "name" , "TestNodeMod2" ) ;
list [ 1 ] . should . have . property ( "module" , "TestNodeModule" ) ;
2014-08-04 18:12:54 +02:00
list [ 1 ] . should . have . property ( "types" , [ "test-node-mod-2" ] ) ;
2014-08-28 01:35:07 +02:00
list [ 1 ] . should . have . property ( "enabled" , true ) ;
2014-08-04 18:12:54 +02:00
list [ 1 ] . should . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-03 22:17:24 +02:00
eventEmitSpy . callCount . should . equal ( 2 ) ;
2014-11-13 16:03:33 +01:00
2014-08-03 22:17:24 +02:00
eventEmitSpy . firstCall . args [ 0 ] . should . be . equal ( "node-icon-dir" ) ;
2014-08-04 12:27:26 +02:00
eventEmitSpy . firstCall . args [ 1 ] . should . be . equal (
resourcesDir + "TestNodeModule" + path . sep + "node_modules" + path . sep + "TestNodeModule" + path . sep + "icons" ) ;
2014-08-03 22:17:24 +02:00
eventEmitSpy . secondCall . args [ 0 ] . should . be . equal ( "type-registered" ) ;
eventEmitSpy . secondCall . args [ 1 ] . should . be . equal ( "test-node-mod-1" ) ;
2014-11-13 16:03:33 +01:00
2014-08-03 22:17:24 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
eventEmitSpy . restore ( ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
it ( 'allows nodes to be added by module name' , function ( done ) {
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settingsWithStorage ) ;
2014-08-04 18:12:54 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . be . empty ;
2014-11-13 16:03:33 +01:00
2015-03-30 22:49:20 +02:00
typeRegistry . addModule ( "TestNodeModule" ) . then ( function ( modInfo ) {
2014-08-04 18:12:54 +02:00
list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 2 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "TestNodeModule/TestNodeMod1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNodeMod1" ) ;
list [ 0 ] . should . have . property ( "module" , "TestNodeModule" ) ;
2014-08-04 18:12:54 +02:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-mod-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
list [ 0 ] . should . not . have . property ( "err" ) ;
2014-11-20 13:15:09 +01:00
list [ 1 ] . should . have . property ( "id" , "TestNodeModule/TestNodeMod2" ) ;
list [ 1 ] . should . have . property ( "name" , "TestNodeMod2" ) ;
list [ 1 ] . should . have . property ( "module" , "TestNodeModule" ) ;
2014-08-04 18:12:54 +02:00
list [ 1 ] . should . have . property ( "types" , [ "test-node-mod-2" ] ) ;
2014-08-28 01:35:07 +02:00
list [ 1 ] . should . have . property ( "enabled" , true ) ;
2014-08-04 18:12:54 +02:00
list [ 1 ] . should . have . property ( "err" ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-11-21 17:35:29 +01:00
it ( 'adds module with version number' , function ( done ) {
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
typeRegistry . init ( settingsWithStorage ) ;
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
typeRegistry . addModule ( "TestNodeModule" , "0.0.1" ) . then ( function ( node ) {
var module = typeRegistry . getModuleInfo ( "TestNodeModule" ) ;
module . should . have . property ( "name" , "TestNodeModule" ) ;
module . should . have . property ( "version" , "0.0.1" ) ;
2014-11-26 16:25:15 +01:00
var modules = typeRegistry . getModuleList ( ) ;
modules [ 0 ] . should . have . property ( "name" , "TestNodeModule" ) ;
modules [ 0 ] . should . have . property ( "version" , "0.0.1" ) ;
2014-11-21 17:35:29 +01:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
it ( 'rejects adding duplicate node modules' , function ( done ) {
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
typeRegistry . init ( settingsWithStorage ) ;
typeRegistry . load ( 'wontexist' , false ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 2 ) ;
typeRegistry . addModule ( "TestNodeModule" ) . then ( function ( node ) {
done ( new Error ( "addModule resolved" ) ) ;
} ) . otherwise ( function ( err ) {
done ( ) ;
} ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-18 22:59:19 +02:00
it ( 'fails to add non-existent module name' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settingsWithStorage ) ;
2014-08-18 22:59:19 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . be . empty ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
typeRegistry . addModule ( "DoesNotExistModule" ) . then ( function ( node ) {
2014-08-18 22:59:19 +02:00
done ( new Error ( "ENOENT not thrown" ) ) ;
} ) . otherwise ( function ( e ) {
e . code . should . eql ( "MODULE_NOT_FOUND" ) ;
done ( ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-18 22:59:19 +02:00
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
it ( 'removes nodes from the registry by module' , function ( done ) {
var fs = require ( "fs" ) ;
var path = require ( "path" ) ;
var pathJoin = ( function ( ) {
var _join = path . join ;
return sinon . stub ( path , "join" , function ( ) {
if ( arguments . length == 3 && arguments [ 2 ] == "package.json" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] , arguments [ 2 ] ) ;
}
if ( arguments . length == 2 && arguments [ 1 ] == "TestNodeModule" ) {
return _join ( resourcesDir , "TestNodeModule" + path . sep + "node_modules" + path . sep , arguments [ 1 ] ) ;
}
return _join . apply ( this , arguments ) ;
} ) ;
} ) ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
var readdirSync = ( function ( ) {
var originalReaddirSync = fs . readdirSync ;
var callCount = 0 ;
return sinon . stub ( fs , "readdirSync" , function ( dir ) {
var result = [ ] ;
if ( callCount == 1 ) {
result = originalReaddirSync ( resourcesDir + "TestNodeModule" + path . sep + "node_modules" ) ;
}
callCount ++ ;
return result ;
} ) ;
} ) ( ) ;
typeRegistry . init ( settingsWithStorage ) ;
typeRegistry . load ( 'wontexist' , false ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 2 ) ;
var res = typeRegistry . removeModule ( "TestNodeModule" ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
res . should . be . an . Array . and . have . lengthOf ( 2 ) ;
res [ 0 ] . should . have . a . property ( "id" , list [ 0 ] . id ) ;
res [ 1 ] . should . have . a . property ( "id" , list [ 1 ] . id ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . be . empty ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) . finally ( function ( ) {
readdirSync . restore ( ) ;
pathJoin . restore ( ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
} ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
it ( 'fails to remove non-existent module name' , function ( done ) {
2015-03-22 23:54:52 +01:00
typeRegistry . init ( settingsWithStorage ) ;
2014-08-28 01:35:07 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . be . empty ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
/*jshint immed: false */
( function ( ) {
typeRegistry . removeModule ( "DoesNotExistModule" ) ;
2015-03-22 23:54:52 +01:00
} ) . should . throw ( "Unrecognised module: DoesNotExistModule" ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
done ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
2014-11-20 13:15:09 +01:00
it ( 'allows nodes to be enabled and disabled by id' , function ( done ) {
2014-08-28 01:35:07 +02:00
typeRegistry . init ( settingsWithStorage ) ;
2014-08-04 18:12:54 +02:00
typeRegistry . load ( resourcesDir + path . sep + "TestNode1" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode1" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-08-04 18:12:54 +02:00
list [ 0 ] . should . have . property ( "enabled" , true ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
var nodeConfig = typeRegistry . getNodeConfigs ( ) ;
nodeConfig . length . should . be . greaterThan ( 0 ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
var info = typeRegistry . disableNode ( list [ 0 ] . id ) ;
info . should . have . property ( "id" , list [ 0 ] . id ) ;
info . should . have . property ( "enabled" , false ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
var list2 = typeRegistry . getNodeList ( ) ;
list2 . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list2 [ 0 ] . should . have . property ( "enabled" , false ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
typeRegistry . getNodeConfigs ( ) . length . should . equal ( 0 ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
var info2 = typeRegistry . enableNode ( list [ 0 ] . id ) ;
info2 . should . have . property ( "id" , list [ 0 ] . id ) ;
info2 . should . have . property ( "enabled" , true ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
var list3 = typeRegistry . getNodeList ( ) ;
list3 . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list3 [ 0 ] . should . have . property ( "enabled" , true ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
var nodeConfig2 = typeRegistry . getNodeConfigs ( ) ;
nodeConfig2 . should . eql ( nodeConfig ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-11-13 16:03:33 +01:00
it ( 'allows nodes to be enabled and disabled by node-type' , function ( done ) {
typeRegistry . init ( settingsWithStorage ) ;
typeRegistry . load ( resourcesDir + path . sep + "TestNode1" , true ) . then ( function ( ) {
var list = typeRegistry . getNodeList ( ) ;
list . should . be . an . Array . and . have . lengthOf ( 1 ) ;
2014-11-20 13:15:09 +01:00
list [ 0 ] . should . have . property ( "id" , "node-red/TestNode1" ) ;
list [ 0 ] . should . have . property ( "name" , "TestNode1" ) ;
list [ 0 ] . should . have . property ( "module" , "node-red" ) ;
2014-11-13 16:03:33 +01:00
list [ 0 ] . should . have . property ( "types" , [ "test-node-1" ] ) ;
list [ 0 ] . should . have . property ( "enabled" , true ) ;
var nodeConfig = typeRegistry . getNodeConfigs ( ) ;
nodeConfig . length . should . be . greaterThan ( 0 ) ;
var info = typeRegistry . disableNode ( list [ 0 ] . types [ 0 ] ) ;
info . should . have . property ( "id" , list [ 0 ] . id ) ;
info . should . have . property ( "types" , list [ 0 ] . types ) ;
info . should . have . property ( "enabled" , false ) ;
var list2 = typeRegistry . getNodeList ( ) ;
list2 . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list2 [ 0 ] . should . have . property ( "enabled" , false ) ;
typeRegistry . getNodeConfigs ( ) . length . should . equal ( 0 ) ;
var info2 = typeRegistry . enableNode ( list [ 0 ] . types [ 0 ] ) ;
info2 . should . have . property ( "id" , list [ 0 ] . id ) ;
info2 . should . have . property ( "types" , list [ 0 ] . types ) ;
info2 . should . have . property ( "enabled" , true ) ;
var list3 = typeRegistry . getNodeList ( ) ;
list3 . should . be . an . Array . and . have . lengthOf ( 1 ) ;
list3 [ 0 ] . should . have . property ( "enabled" , true ) ;
var nodeConfig2 = typeRegistry . getNodeConfigs ( ) ;
nodeConfig2 . should . eql ( nodeConfig ) ;
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2014-08-28 01:35:07 +02:00
it ( 'fails to enable/disable non-existent nodes' , function ( done ) {
2014-11-27 17:42:45 +01:00
typeRegistry . init ( settingsWithStorage ) ;
2014-08-28 01:35:07 +02:00
typeRegistry . load ( "wontexist" , true ) . then ( function ( ) {
2014-08-04 18:12:54 +02:00
var list = typeRegistry . getNodeList ( ) ;
2014-08-28 01:35:07 +02:00
list . should . be . an . Array . and . be . empty ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
/*jshint immed: false */
( function ( ) {
2014-11-27 17:42:45 +01:00
typeRegistry . disableNode ( "123" ) ;
2014-08-04 18:12:54 +02:00
} ) . should . throw ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-28 01:35:07 +02:00
/*jshint immed: false */
( function ( ) {
typeRegistry . enableNode ( "123" ) ;
} ) . should . throw ( ) ;
2014-11-13 16:03:33 +01:00
2014-08-04 18:12:54 +02:00
done ( ) ;
} ) . catch ( function ( e ) {
done ( e ) ;
} ) ;
} ) ;
2015-03-22 23:54:52 +01:00
it ( "handles unavailable settings" , function ( done ) {
typeRegistry . init ( settings ) ;
/*jshint immed: false */
( function ( ) {
typeRegistry . enableNode ( "123" ) ;
} ) . should . throw ( "Settings unavailable" ) ;
/*jshint immed: false */
( function ( ) {
typeRegistry . disableNode ( "123" ) ;
} ) . should . throw ( "Settings unavailable" ) ;
/*jshint immed: false */
( function ( ) {
typeRegistry . addModule ( "123" ) ;
} ) . should . throw ( "Settings unavailable" ) ;
/*jshint immed: false */
( function ( ) {
typeRegistry . removeModule ( "123" ) ;
} ) . should . throw ( "Settings unavailable" ) ;
done ( ) ;
} ) ;
2014-07-30 19:07:20 +02:00
} ) ;