@@ -45,14 +45,16 @@ module.exports = () => {
45
45
const consoleSpy = sinon . spy ( console , 'log' ) ;
46
46
47
47
// handle correct request
48
- const deployServer = nock ( 'http://localhost:8080' ) . post ( '/deploy' ) . reply ( ( uri , requestBody , cb ) => {
49
- const excgf = fs . readFileSync ( path . join ( testFolder , 'exoframe.json' ) ) ;
50
- const index = fs . readFileSync ( path . join ( testFolder , 'index.html' ) ) ;
51
- t . ok ( requestBody . includes ( excgf ) , 'Should send correct config' ) ;
52
- t . ok ( requestBody . includes ( index ) , 'Should send correct index file' ) ;
48
+ const deployServer = nock ( 'http://localhost:8080' )
49
+ . post ( '/deploy' )
50
+ . reply ( ( uri , requestBody , cb ) => {
51
+ const excgf = fs . readFileSync ( path . join ( testFolder , 'exoframe.json' ) ) ;
52
+ const index = fs . readFileSync ( path . join ( testFolder , 'index.html' ) ) ;
53
+ t . ok ( requestBody . includes ( excgf ) , 'Should send correct config' ) ;
54
+ t . ok ( requestBody . includes ( index ) , 'Should send correct index file' ) ;
53
55
54
- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
55
- } ) ;
56
+ cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
57
+ } ) ;
56
58
57
59
// execute login
58
60
deploy ( { _ : [ folderPath ] } ) . then ( ( ) => {
@@ -83,9 +85,11 @@ module.exports = () => {
83
85
const consoleSpy = sinon . spy ( console , 'log' ) ;
84
86
85
87
// handle correct request
86
- const deployServer = nock ( 'http://localhost:8080' ) . post ( '/deploy' ) . reply ( ( uri , requestBody , cb ) => {
87
- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
88
- } ) ;
88
+ const deployServer = nock ( 'http://localhost:8080' )
89
+ . post ( '/deploy' )
90
+ . reply ( ( uri , requestBody , cb ) => {
91
+ cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
92
+ } ) ;
89
93
90
94
// execute login
91
95
deploy ( ) . then ( ( ) => {
@@ -118,9 +122,11 @@ module.exports = () => {
118
122
const originalConfig = Object . assign ( { } , userConfig ) ;
119
123
120
124
// handle correct request
121
- const deployServer = nock ( 'http://localhost:8080' ) . post ( '/deploy' ) . reply ( ( uri , requestBody , cb ) => {
122
- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
123
- } ) ;
125
+ const deployServer = nock ( 'http://localhost:8080' )
126
+ . post ( '/deploy' )
127
+ . reply ( ( uri , requestBody , cb ) => {
128
+ cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
129
+ } ) ;
124
130
125
131
// remove auth from config
126
132
updateConfig ( { endpoint : 'http://localhost:8080' } ) ;
@@ -157,9 +163,11 @@ module.exports = () => {
157
163
const consoleSpy = sinon . spy ( console , 'log' ) ;
158
164
159
165
// handle correct request
160
- const updateServer = nock ( 'http://localhost:8080' ) . post ( '/update' ) . reply ( ( uri , requestBody , cb ) => {
161
- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
162
- } ) ;
166
+ const updateServer = nock ( 'http://localhost:8080' )
167
+ . post ( '/update' )
168
+ . reply ( ( uri , requestBody , cb ) => {
169
+ cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
170
+ } ) ;
163
171
164
172
// execute login
165
173
deploy ( { update : true } ) . then ( ( ) => {
@@ -190,9 +198,11 @@ module.exports = () => {
190
198
const consoleSpy = sinon . spy ( console , 'log' ) ;
191
199
192
200
// handle correct request
193
- const deployServer = nock ( 'http://localhost:8080' ) . post ( '/deploy' ) . reply ( ( uri , requestBody , cb ) => {
194
- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
195
- } ) ;
201
+ const deployServer = nock ( 'http://localhost:8080' )
202
+ . post ( '/deploy' )
203
+ . reply ( ( uri , requestBody , cb ) => {
204
+ cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
205
+ } ) ;
196
206
197
207
// execute
198
208
deploy ( { open : true } ) . then ( ( ) => {
@@ -225,19 +235,21 @@ module.exports = () => {
225
235
const consoleSpy = sinon . spy ( console , 'log' ) ;
226
236
227
237
// handle correct request
228
- const deployServer = nock ( 'http://localhost:8080' ) . post ( '/deploy' ) . reply ( ( uri , requestBody , cb ) => {
229
- cb ( null , [
230
- 400 ,
231
- {
232
- status : 'error' ,
233
- result : {
234
- error : 'Build failed! See build log for details.' ,
235
- log : [ 'Error log' , 'here' ] ,
236
- image : 'test:latest' ,
238
+ const deployServer = nock ( 'http://localhost:8080' )
239
+ . post ( '/deploy' )
240
+ . reply ( ( uri , requestBody , cb ) => {
241
+ cb ( null , [
242
+ 400 ,
243
+ {
244
+ status : 'error' ,
245
+ result : {
246
+ error : 'Build failed! See build log for details.' ,
247
+ log : [ 'Error log' , 'here' ] ,
248
+ image : 'test:latest' ,
249
+ } ,
237
250
} ,
238
- } ,
239
- ] ) ;
240
- } ) ;
251
+ ] ) ;
252
+ } ) ;
241
253
242
254
// execute
243
255
deploy ( ) . then ( ( ) => {
@@ -264,6 +276,42 @@ module.exports = () => {
264
276
} ) ;
265
277
} ) ;
266
278
279
+ // test
280
+ tap . test ( 'Should display error on malformed JSON' , t => {
281
+ // spy on console
282
+ const consoleSpy = sinon . spy ( console , 'log' ) ;
283
+
284
+ // handle correct request
285
+ const deployServer = nock ( 'http://localhost:8080' )
286
+ . post ( '/deploy' )
287
+ . reply ( ( uri , requestBody , cb ) => {
288
+ cb ( null , [ 200 , 'Bad Gateway' ] ) ;
289
+ } ) ;
290
+
291
+ // execute
292
+ deploy ( ) . then ( ( ) => {
293
+ // make sure log in was successful
294
+ // check that server was called
295
+ t . ok ( deployServer . isDone ( ) ) ;
296
+ // first check console output
297
+ t . deepEqual (
298
+ consoleSpy . args ,
299
+ [
300
+ [ 'Deploying current project to endpoint:' , 'http://localhost:8080' ] ,
301
+ [ 'Error deploying project:' , 'Bad Gateway' ] ,
302
+ [ 'Build log:\n' ] ,
303
+ [ 'No log available' ] ,
304
+ ] ,
305
+ 'Correct log output'
306
+ ) ;
307
+ // restore console
308
+ console . log . restore ( ) ;
309
+ // tear down nock
310
+ deployServer . done ( ) ;
311
+ t . end ( ) ;
312
+ } ) ;
313
+ } ) ;
314
+
267
315
// test
268
316
tap . test ( 'Should not deploy with broken config' , t => {
269
317
// spy on console
@@ -317,7 +365,9 @@ module.exports = () => {
317
365
// copy original config for restoration
318
366
const originalConfig = Object . assign ( { } , userConfig ) ;
319
367
// handle correct request
320
- const deployServer = nock ( 'http://localhost:8080' ) . post ( '/deploy' ) . reply ( 401 , { error : 'Deauth test' } ) ;
368
+ const deployServer = nock ( 'http://localhost:8080' )
369
+ . post ( '/deploy' )
370
+ . reply ( 401 , { error : 'Deauth test' } ) ;
321
371
// spy on console
322
372
const consoleSpy = sinon . spy ( console , 'log' ) ;
323
373
// execute login
0 commit comments