18
18
const path = require ( "path" ) ;
19
19
const sinon = require ( "sinon" ) ;
20
20
const should = require ( 'should' ) ;
21
+ const fs = require ( 'fs' ) ;
21
22
require ( 'should-sinon' ) ;
22
- const when = require ( "when" ) ;
23
23
const request = require ( 'supertest' ) ;
24
24
const express = require ( "express" ) ;
25
25
const http = require ( 'http' ) ;
@@ -84,7 +84,7 @@ class NodeTestHelper extends EventEmitter {
84
84
// public runtime API
85
85
this . _log = RED . log ;
86
86
// access internal Node-RED runtime methods
87
- const prefix = path . dirname ( requirePath ) ;
87
+ let prefix = path . dirname ( requirePath ) ;
88
88
if ( checkSemver ( RED . version ( ) , "<0.20.0" ) ) {
89
89
this . _settings = RED . settings ;
90
90
this . _events = RED . events ;
@@ -96,19 +96,25 @@ class NodeTestHelper extends EventEmitter {
96
96
// information about the latest call
97
97
this . _NodePrototype = require ( path . join ( prefix , 'runtime' , 'nodes' , 'Node' ) ) . prototype ;
98
98
} else {
99
- // This is good enough for running it within the NR git repository - given the
100
- // code layout changes. But it will need some more work when running in the other
101
- // possible locations
99
+ if ( ! fs . existsSync ( path . join ( prefix , '@node-red/runtime/lib/nodes' ) ) ) {
100
+ // Not in the NR source tree, need to go hunting for the modules....
101
+ if ( / n o d e _ m o d u l e s \/ n o d e - r e d \/ l i b $ / . test ( prefix ) ) {
102
+ prefix = path . resolve ( path . join ( prefix , ".." , ".." ) ) ;
103
+ } else {
104
+ throw new Error ( "Cannot find the NR source tree. Please raise an issue against node-red/node-red-node-test-helper with full details." ) ;
105
+ }
106
+ }
107
+
102
108
this . _redNodes = require ( path . join ( prefix , '@node-red/runtime/lib/nodes' ) ) ;
103
- this . _settings = RED . settings ;
104
- this . _events = RED . runtime . events ;
105
109
this . _context = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/context' ) ) ;
106
110
this . _comms = require ( path . join ( prefix , '@node-red/editor-api/lib/editor/comms' ) ) ;
107
111
this . _registryUtil = require ( path . join ( prefix , '@node-red/registry/lib/util' ) ) ;
108
112
this . credentials = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/credentials' ) ) ;
109
113
// proxy the methods on Node.prototype to both be Sinon spies and asynchronously emit
110
114
// information about the latest call
111
115
this . _NodePrototype = require ( path . join ( prefix , '@node-red/runtime/lib/nodes/Node' ) ) . prototype ;
116
+ this . _settings = RED . settings ;
117
+ this . _events = RED . runtime . events ;
112
118
}
113
119
} catch ( ignored ) {
114
120
console . log ( ignored ) ;
@@ -157,7 +163,7 @@ class NodeTestHelper extends EventEmitter {
157
163
158
164
var storage = {
159
165
getFlows : function ( ) {
160
- return when . resolve ( { flows :testFlow , credentials :testCredentials } ) ;
166
+ return Promise . resolve ( { flows :testFlow , credentials :testCredentials } ) ;
161
167
}
162
168
} ;
163
169
// this._settings.logging = {console:{level:'off'}};
0 commit comments