@@ -82,12 +82,13 @@ class NodeTestHelper extends EventEmitter {
8282 try {
8383 const RED = this . _RED = require ( requirePath ) ;
8484 // public runtime API
85- this . _redNodes = RED . nodes ;
86- this . _events = RED . events ;
8785 this . _log = RED . log ;
8886 // access internal Node-RED runtime methods
8987 const prefix = path . dirname ( requirePath ) ;
9088 if ( checkSemver ( RED . version ( ) , "<0.20.0" ) ) {
89+ this . _settings = RED . settings ;
90+ this . _events = RED . events ;
91+ this . _redNodes = RED . nodes ;
9192 this . _context = require ( path . join ( prefix , 'runtime' , 'nodes' , 'context' ) ) ;
9293 this . _comms = require ( path . join ( prefix , 'api' , 'editor' , 'comms' ) ) ;
9394 this . credentials = require ( path . join ( prefix , 'runtime' , 'nodes' , 'credentials' ) ) ;
@@ -98,8 +99,12 @@ class NodeTestHelper extends EventEmitter {
9899 // This is good enough for running it within the NR git repository - given the
99100 // code layout changes. But it will need some more work when running in the other
100101 // possible locations
102+ this . _redNodes = require ( path . join ( prefix , '@node-red/runtime/lib/nodes' ) ) ;
103+ this . _settings = RED . settings ;
104+ this . _events = RED . runtime . events ;
101105 this . _context = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/context' ) ) ;
102106 this . _comms = require ( path . join ( prefix , '@node-red/editor-api/lib/editor/comms' ) ) ;
107+ this . _registryUtil = require ( path . join ( prefix , '@node-red/registry/lib/util' ) ) ;
103108 this . credentials = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/credentials' ) ) ;
104109 // proxy the methods on Node.prototype to both be Sinon spies and asynchronously emit
105110 // information about the latest call
@@ -155,40 +160,53 @@ class NodeTestHelper extends EventEmitter {
155160 return when . resolve ( { flows :testFlow , credentials :testCredentials } ) ;
156161 }
157162 } ;
158-
159- var settings = {
160- available : function ( ) { return false ; }
161- } ;
162-
163- var red = {
164- _ : v => v
165- } ;
166-
167- Object . keys ( this . _RED ) . filter ( prop => ! / ^ ( i n i t | s t a r t | s t o p ) $ / . test ( prop ) )
168- . forEach ( prop => {
169- const propDescriptor = Object . getOwnPropertyDescriptor ( this . _RED , prop ) ;
170- Object . defineProperty ( red , prop , propDescriptor ) ;
171- } ) ;
163+ // this._settings.logging = {console:{level:'off'}};
164+ this . _settings . available = function ( ) { return false ; }
172165
173166 const redNodes = this . _redNodes ;
174- redNodes . init ( {
167+ this . _httpAdmin = express ( ) ;
168+ const mockRuntime = {
169+ nodes : redNodes ,
175170 events : this . _events ,
176- settings : settings ,
171+ util : this . _RED . util ,
172+ settings : this . _settings ,
177173 storage : storage ,
178- log : this . _log
179- } ) ;
174+ log : this . _log ,
175+ nodeApp : express ( ) ,
176+ adminApp : this . _httpAdmin ,
177+ library : { register : function ( ) { } } ,
178+ get server ( ) { return self . _server }
179+ }
180+
181+ redNodes . init ( mockRuntime ) ;
180182 redNodes . registerType ( "helper" , function ( n ) {
181183 redNodes . createNode ( this , n ) ;
182184 } ) ;
183185
186+ var red ;
187+ if ( this . _registryUtil ) {
188+ this . _registryUtil . init ( mockRuntime ) ;
189+ red = this . _registryUtil . createNodeApi ( { } ) ;
190+ red . _ = v => v ;
191+ red . settings = this . _settings ;
192+ } else {
193+ red = {
194+ _ : v => v
195+ } ;
196+ Object . keys ( this . _RED ) . filter ( prop => ! / ^ ( i n i t | s t a r t | s t o p ) $ / . test ( prop ) )
197+ . forEach ( prop => {
198+ const propDescriptor = Object . getOwnPropertyDescriptor ( this . _RED , prop ) ;
199+ Object . defineProperty ( red , prop , propDescriptor ) ;
200+ } ) ;
201+ }
202+
184203 if ( Array . isArray ( testNode ) ) {
185204 testNode . forEach ( fn => {
186205 fn ( red ) ;
187206 } ) ;
188207 } else {
189208 testNode ( red ) ;
190209 }
191-
192210 redNodes . loadFlows ( )
193211 . then ( ( ) => {
194212 redNodes . startFlows ( ) ;
@@ -222,7 +240,7 @@ class NodeTestHelper extends EventEmitter {
222240 }
223241
224242 request ( ) {
225- return request ( this . _RED . httpAdmin ) ;
243+ return request ( this . _httpAdmin ) ;
226244 }
227245
228246 startServer ( done ) {
@@ -231,8 +249,7 @@ class NodeTestHelper extends EventEmitter {
231249 this . _app ( req , res ) ;
232250 } ) , 0 ) ;
233251
234- this . _RED . init ( server , {
235- SKIP_BUILD_CHECK : true ,
252+ this . _RED . init ( server , {
236253 logging :{ console :{ level :'off' } }
237254 } ) ;
238255 server . listen ( this . _listenPort , this . _address ) ;
0 commit comments