2
2
3
3
var test = require ( 'tape' ) ,
4
4
sinon = require ( 'sinon' ) ;
5
- var path = require ( 'path' ) ;
6
- var embeddedStart = require ( '../' ) ;
7
-
8
- const REDsettings = {
9
- httpAdminRoot : false ,
10
- httpNodeRoot : false ,
11
- functionGlobalContext : { } ,
12
- disableEditor : true ,
13
- userDir : path . join ( __dirname , '.node-red' ) ,
14
- logging : {
15
- console : {
16
- level : process . env . NODE_RED_LOGLEVEL || "info"
17
- }
18
- }
19
- } ;
5
+ var embeddedStart = require ( '../' ) ,
6
+ fixture = require ( './fixture' ) ;
20
7
21
8
var RED ;
22
9
var REDevents ;
23
10
var testFlow ;
24
11
25
- function failAndEnd ( t ) {
26
- return ( err ) => {
27
- t . fail ( err ) ;
28
- t . end ( ) ;
29
- } ;
30
- }
31
-
32
12
test . onFinish ( function ( ) {
33
-
34
- function closeUp ( ) {
35
- let prom = testFlow ? RED . nodes . removeFlow ( testFlow ) : Promise . resolve ( ) ;
36
- if ( RED ) {
37
- prom = prom . then ( ( ) => RED . stop ( ) ) ;
38
- }
39
- prom . catch ( ( e ) => {
40
- console . error ( "stopping Node-RED failed:" ) ;
41
- console . error ( e . stack ? e . stack : e ) ;
42
- } ) ;
43
- }
44
-
45
- closeUp ( ) ;
13
+ fixture . closeUp ( RED , testFlow ) ;
46
14
} ) ;
47
15
48
16
test ( 'can create and initialize Node-RED runtime' , function ( t ) {
49
17
t . plan ( 3 ) ;
50
18
51
19
t . doesNotThrow ( ( ) => {
52
20
RED = require ( 'node-red' ) ;
53
- } , undefined , 'instantiates Node-RED runtime without error' ) ;
54
- t . doesNotThrow ( RED . init . bind ( RED , undefined , REDsettings ) ,
55
- undefined ,
56
- 'initializes Node-RED runtime without error' ) ;
21
+ } , undefined , 'loads Node-RED module without error' ) ;
22
+ t . doesNotThrow (
23
+ RED . init . bind ( RED , undefined , fixture . settings ) ,
24
+ undefined ,
25
+ 'initializes Node-RED runtime without error' ) ;
57
26
t . doesNotThrow ( ( ) => {
58
27
REDevents = require ( 'node-red/red/runtime/events' ) ;
59
- } , undefined , 'loads RED events object without erorr ' ) ;
28
+ } , undefined , 'loads Node- RED events module without error ' ) ;
60
29
} ) ;
61
30
62
31
test ( 'can be used to generate wait function' , function ( t ) {
@@ -84,7 +53,7 @@ test('can be used to promise waiting for \'nodes-started\'', function(t) {
84
53
spy ( ) ;
85
54
tt . pass ( 'resolves once nodes-started event fires' ) ;
86
55
tt . equal ( result , REDresult , 'passes result through' ) ;
87
- } ) . catch ( failAndEnd ( tt ) ) ;
56
+ } ) . catch ( fixture . failAndEnd ( tt ) ) ;
88
57
setTimeout ( ( ) => {
89
58
tt . ok ( spy . notCalled , 'does not resolve before node-started event fires' ) ;
90
59
REDevents . emit ( 'nodes-started' ) ;
@@ -116,7 +85,7 @@ test('generated function promises to wait for \'nodes-started\'', function(t) {
116
85
spy ( ) ;
117
86
t . pass ( 'resolves once nodes-started event fires' ) ;
118
87
t . equal ( result , REDresult , 'passes result through' ) ;
119
- } ) . catch ( failAndEnd ( t ) ) ;
88
+ } ) . catch ( fixture . failAndEnd ( t ) ) ;
120
89
setTimeout ( ( ) => {
121
90
t . ok ( spy . notCalled , 'does not resolve before node-started event fires' ) ;
122
91
REDevents . emit ( 'nodes-started' ) ;
@@ -195,7 +164,7 @@ test('waiting for \'nodes-started\' results in flow API ready', function(t) {
195
164
t . doesNotThrow ( ( ) => addFlow ( t , true ) ,
196
165
undefined ,
197
166
'addFlow() now returns without error' ) ;
198
- } ) . catch ( failAndEnd ( t ) ) ;
167
+ } ) . catch ( fixture . failAndEnd ( t ) ) ;
199
168
} ) ;
200
169
201
170
test ( 'generated function resolves immediately if flows API ready' , function ( t ) {
@@ -208,7 +177,7 @@ test('generated function resolves immediately if flows API ready', function(t) {
208
177
spy ( ) ;
209
178
t . pass ( 'wait function resolves immediately when flows API ready' ) ;
210
179
t . equal ( result , REDresult , 'and passes result through' ) ;
211
- } ) . catch ( failAndEnd ( t ) ) ;
180
+ } ) . catch ( fixture . failAndEnd ( t ) ) ;
212
181
setTimeout ( ( ) => {
213
182
t . ok ( spy . calledOnce , 'has resolved before timeout and without event' ) ;
214
183
} , 10 ) ;
0 commit comments