@@ -5,6 +5,8 @@ const path = require('path');
55const nock = require ( 'nock' ) ;
66const sinon = require ( 'sinon' ) ;
77const proxyquire = require ( 'proxyquire' ) ;
8+ const _ = require ( 'highland' ) ;
9+ const { Readable} = require ( 'stream' ) ;
810
911// our packages
1012const { userConfig, updateConfig} = require ( '../src/config' ) ;
@@ -15,6 +17,14 @@ const opnStub = sinon.spy();
1517// require deploy with stub for opn
1618const { handler : deploy } = proxyquire ( '../src/commands/deploy' , { opn : opnStub } ) ;
1719
20+ // reply with stream helper
21+ const replyWithStream = dataArr => {
22+ const replyStream = _ ( ) ;
23+ dataArr . forEach ( data => replyStream . write ( JSON . stringify ( data ) ) ) ;
24+ replyStream . end ( '' ) ;
25+ return new Readable ( ) . wrap ( replyStream ) ;
26+ } ;
27+
1828module . exports = ( ) => {
1929 const folder = 'test_html_project' ;
2030 const folderPath = path . join ( 'test' , 'fixtures' , folder ) ;
@@ -47,13 +57,13 @@ module.exports = () => {
4757 // handle correct request
4858 const deployServer = nock ( 'http://localhost:8080' )
4959 . post ( '/deploy' )
50- . reply ( ( uri , requestBody , cb ) => {
60+ . reply ( ( uri , requestBody ) => {
5161 const excgf = fs . readFileSync ( path . join ( testFolder , 'exoframe.json' ) ) ;
5262 const index = fs . readFileSync ( path . join ( testFolder , 'index.html' ) ) ;
5363 t . ok ( requestBody . includes ( excgf ) , 'Should send correct config' ) ;
5464 t . ok ( requestBody . includes ( index ) , 'Should send correct index file' ) ;
5565
56- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
66+ return replyWithStream ( [ { message : 'Deployment success! ' , deployments, level : 'info' } ] ) ;
5767 } ) ;
5868
5969 // execute login
@@ -87,9 +97,7 @@ module.exports = () => {
8797 // handle correct request
8898 const deployServer = nock ( 'http://localhost:8080' )
8999 . post ( '/deploy' )
90- . reply ( ( uri , requestBody , cb ) => {
91- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
92- } ) ;
100+ . reply ( ( ) => replyWithStream ( [ { message : 'Deployment success!' , deployments, level : 'info' } ] ) ) ;
93101
94102 // execute login
95103 deploy ( ) . then ( ( ) => {
@@ -124,9 +132,7 @@ module.exports = () => {
124132 // handle correct request
125133 const deployServer = nock ( 'http://localhost:8080' )
126134 . post ( '/deploy' )
127- . reply ( ( uri , requestBody , cb ) => {
128- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
129- } ) ;
135+ . reply ( ( ) => replyWithStream ( [ { message : 'Deployment success!' , deployments, level : 'info' } ] ) ) ;
130136
131137 // remove auth from config
132138 updateConfig ( { endpoint : 'http://localhost:8080' } ) ;
@@ -141,7 +147,7 @@ module.exports = () => {
141147 consoleSpy . args ,
142148 [
143149 [ 'Deploying current project to endpoint:' , 'http://localhost:8080' ] ,
144- [ 'Deploying using given token..' ] ,
150+ [ '\nDeploying using given token..' ] ,
145151 [ 'Your project is now deployed as:\n' ] ,
146152 [ ' ID URL Hostname \n test localhost test ' ] ,
147153 ] ,
@@ -165,9 +171,7 @@ module.exports = () => {
165171 // handle correct request
166172 const updateServer = nock ( 'http://localhost:8080' )
167173 . post ( '/update' )
168- . reply ( ( uri , requestBody , cb ) => {
169- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
170- } ) ;
174+ . reply ( ( ) => replyWithStream ( [ { message : 'Deployment success!' , deployments, level : 'info' } ] ) ) ;
171175
172176 // execute login
173177 deploy ( { update : true } ) . then ( ( ) => {
@@ -200,9 +204,7 @@ module.exports = () => {
200204 // handle correct request
201205 const deployServer = nock ( 'http://localhost:8080' )
202206 . post ( '/deploy' )
203- . reply ( ( uri , requestBody , cb ) => {
204- cb ( null , [ 200 , { status : 'success' , deployments} ] ) ;
205- } ) ;
207+ . reply ( ( ) => replyWithStream ( [ { message : 'Deployment success!' , deployments, level : 'info' } ] ) ) ;
206208
207209 // execute
208210 deploy ( { open : true } ) . then ( ( ) => {
@@ -237,19 +239,16 @@ module.exports = () => {
237239 // handle correct request
238240 const deployServer = nock ( 'http://localhost:8080' )
239241 . post ( '/deploy' )
240- . reply ( ( uri , requestBody , cb ) => {
241- cb ( null , [
242- 400 ,
242+ . reply ( ( ) =>
243+ replyWithStream ( [
243244 {
244- status : 'error' ,
245- result : {
246- error : 'Build failed! See build log for details.' ,
247- log : [ 'Error log' , 'here' ] ,
248- image : 'test:latest' ,
249- } ,
245+ message : 'Build failed! See build log for details.' ,
246+ error : 'Build failed! See build log for details.' ,
247+ log : [ 'Error log' , 'here' ] ,
248+ level : 'error' ,
250249 } ,
251- ] ) ;
252- } ) ;
250+ ] )
251+ ) ;
253252
254253 // execute
255254 deploy ( ) . then ( ( ) => {
@@ -331,37 +330,24 @@ module.exports = () => {
331330 t . ok ( deployServer . isDone ( ) ) ;
332331 // first check console output
333332 t . deepEqual (
334- consoleSpy . args ,
333+ // check beginning of log
334+ consoleSpy . args . slice ( 0 , consoleSpy . args . length - 1 ) ,
335335 [
336336 [ 'Deploying current project to endpoint:' , 'http://localhost:8080' ] ,
337337 [ '\nIgnoring following paths:' , [ '.git' , 'node_modules' ] ] ,
338+ [ '[error]' , 'Error parsing line:' , 'Bad Gateway' ] ,
338339 [ 'Error deploying project:' , 'Bad Gateway' ] ,
339340 [ 'Build log:\n' ] ,
340341 [ 'No log available' ] ,
341342 [ '' ] ,
342- [
343- 'Original error:' ,
344- {
345- response : {
346- result : {
347- error : 'Bad Gateway' ,
348- log : [ 'No log available' ] ,
349- } ,
350- } ,
351- } ,
352- ] ,
353- [
354- 'Original response:' ,
355- {
356- result : {
357- error : 'Bad Gateway' ,
358- log : [ 'No log available' ] ,
359- } ,
360- } ,
361- ] ,
362343 ] ,
363344 'Correct log output'
364345 ) ;
346+ // check error correctness
347+ const err = consoleSpy . args [ consoleSpy . args . length - 1 ] [ 1 ] ;
348+ t . equal ( err . message , 'Error parsing output!' , 'Correct error text' ) ;
349+ t . ok ( err . response , 'Has response' ) ;
350+ t . equal ( err . response . error , 'Bad Gateway' , 'Correct error response' ) ;
365351 // restore console
366352 console . log . restore ( ) ;
367353 // tear down nock
0 commit comments