@@ -82,12 +82,13 @@ class NodeTestHelper extends EventEmitter {
82
82
try {
83
83
const RED = this . _RED = require ( requirePath ) ;
84
84
// public runtime API
85
- this . _redNodes = RED . nodes ;
86
- this . _events = RED . events ;
87
85
this . _log = RED . log ;
88
86
// access internal Node-RED runtime methods
89
87
const prefix = path . dirname ( requirePath ) ;
90
88
if ( checkSemver ( RED . version ( ) , "<0.20.0" ) ) {
89
+ this . _settings = RED . settings ;
90
+ this . _events = RED . events ;
91
+ this . _redNodes = RED . nodes ;
91
92
this . _context = require ( path . join ( prefix , 'runtime' , 'nodes' , 'context' ) ) ;
92
93
this . _comms = require ( path . join ( prefix , 'api' , 'editor' , 'comms' ) ) ;
93
94
this . credentials = require ( path . join ( prefix , 'runtime' , 'nodes' , 'credentials' ) ) ;
@@ -98,8 +99,12 @@ class NodeTestHelper extends EventEmitter {
98
99
// This is good enough for running it within the NR git repository - given the
99
100
// code layout changes. But it will need some more work when running in the other
100
101
// 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 ;
101
105
this . _context = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/context' ) ) ;
102
106
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' ) ) ;
103
108
this . credentials = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/credentials' ) ) ;
104
109
// proxy the methods on Node.prototype to both be Sinon spies and asynchronously emit
105
110
// information about the latest call
@@ -155,40 +160,53 @@ class NodeTestHelper extends EventEmitter {
155
160
return when . resolve ( { flows :testFlow , credentials :testCredentials } ) ;
156
161
}
157
162
} ;
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 ; }
172
165
173
166
const redNodes = this . _redNodes ;
174
- redNodes . init ( {
167
+ this . _httpAdmin = express ( ) ;
168
+ const mockRuntime = {
169
+ nodes : redNodes ,
175
170
events : this . _events ,
176
- settings : settings ,
171
+ util : this . _RED . util ,
172
+ settings : this . _settings ,
177
173
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 ) ;
180
182
redNodes . registerType ( "helper" , function ( n ) {
181
183
redNodes . createNode ( this , n ) ;
182
184
} ) ;
183
185
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
+
184
203
if ( Array . isArray ( testNode ) ) {
185
204
testNode . forEach ( fn => {
186
205
fn ( red ) ;
187
206
} ) ;
188
207
} else {
189
208
testNode ( red ) ;
190
209
}
191
-
192
210
redNodes . loadFlows ( )
193
211
. then ( ( ) => {
194
212
redNodes . startFlows ( ) ;
@@ -222,7 +240,7 @@ class NodeTestHelper extends EventEmitter {
222
240
}
223
241
224
242
request ( ) {
225
- return request ( this . _RED . httpAdmin ) ;
243
+ return request ( this . _httpAdmin ) ;
226
244
}
227
245
228
246
startServer ( done ) {
@@ -231,8 +249,7 @@ class NodeTestHelper extends EventEmitter {
231
249
this . _app ( req , res ) ;
232
250
} ) , 0 ) ;
233
251
234
- this . _RED . init ( server , {
235
- SKIP_BUILD_CHECK : true ,
252
+ this . _RED . init ( server , {
236
253
logging :{ console :{ level :'off' } }
237
254
} ) ;
238
255
server . listen ( this . _listenPort , this . _address ) ;
0 commit comments