15
15
16
16
var spawn = require ( 'child_process' ) . spawn ;
17
17
var request = require ( 'request' ) ;
18
+ var async = require ( 'async' ) ;
18
19
19
20
var cwd = process . cwd ( ) ;
20
21
@@ -25,6 +26,7 @@ function getPath(dir) {
25
26
var sampleTests = [
26
27
{
27
28
dir : 'express' ,
29
+ projectId : 'express-demo' ,
28
30
cmd : 'node' ,
29
31
arg1 : './bin/www' ,
30
32
msg : 'Hello World! Express.js on Google App Engine.'
@@ -93,6 +95,36 @@ if (process.env.TRAVIS_NODE_VERSION !== 'stable') {
93
95
} ) ;
94
96
}
95
97
98
+ function end ( timeoutId , intervalId , proc ) {
99
+ clearTimeout ( timeoutId ) ;
100
+ clearInterval ( intervalId ) ;
101
+ proc . kill ( 'SIGKILL' ) ;
102
+ }
103
+
104
+ function testRequest ( url , sample , cb ) {
105
+ request ( url , function ( err , res , body ) {
106
+ if ( err ) {
107
+ cb ( err , false ) ;
108
+ } else {
109
+ if ( body && body . indexOf ( sample . msg ) !== - 1 &&
110
+ ( res . statusCode === 200 || res . statusCode === sample . code ) ) {
111
+ cb ( null , true ) ;
112
+ } else {
113
+ cb ( null , false ) ;
114
+ }
115
+ }
116
+ } ) ;
117
+ }
118
+
119
+ function shouldHide ( data ) {
120
+ if ( data && ( data . indexOf ( '.../' ) !== - 1 ||
121
+ data . indexOf ( '...-' ) !== - 1 ||
122
+ data . indexOf ( '...\\' ) !== - 1 ||
123
+ data . indexOf ( '...|' ) !== - 1 ) ) {
124
+ return true ;
125
+ }
126
+ }
127
+
96
128
describe ( 'appengine/' , function ( ) {
97
129
sampleTests . forEach ( function ( sample ) {
98
130
it ( sample . dir + ': dependencies should install' , function ( done ) {
@@ -166,24 +198,110 @@ describe('appengine/', function () {
166
198
}
167
199
} ) ;
168
200
169
- timeoutId = setTimeout ( end , 5000 ) ;
170
- intervalId = setInterval ( testRequest , 1000 ) ;
201
+ timeoutId = setTimeout ( function ( ) {
202
+ end ( timeoutId , intervalId , proc ) ;
203
+ } , 10000 ) ;
204
+
205
+ // Give the server time to start up
206
+ setTimeout ( function ( ) {
207
+ intervalId = setInterval ( function ( ) {
208
+ var url = 'http://localhost:8080' ;
209
+ testRequest ( url , sample , function ( err , _success ) {
210
+ if ( err ) {
211
+ console . log ( err ) ;
212
+ } else {
213
+ success = _success ;
214
+ }
215
+ end ( timeoutId , intervalId , proc ) ;
216
+ } ) ;
217
+ } , 1000 ) ;
218
+ } , 2000 ) ;
219
+ } ) ;
220
+ } ) ;
221
+
222
+ if ( ! process . env . TRAVIS ) {
223
+ return ;
224
+ }
171
225
172
- function end ( ) {
173
- clearTimeout ( timeoutId ) ;
174
- clearInterval ( intervalId ) ;
175
- proc . kill ( 'SIGKILL' ) ;
176
- }
226
+ it ( 'should deploy all samples' , function ( done ) {
227
+ this . timeout ( 10 * 60 * 1000 ) ; // 10 minutes
228
+ async . parallel ( sampleTests . map ( function ( sample ) {
229
+ if ( sample . projectId ) {
230
+ return function ( cb ) {
231
+ var calledDone = false ;
232
+ var proc = spawn ( 'gcloud' , [
233
+ 'preview' ,
234
+ 'app' ,
235
+ 'deploy' ,
236
+ 'app.yaml' ,
237
+ '-q' ,
238
+ '--project' ,
239
+ sample . projectId ,
240
+ '--promote' ,
241
+ '--version' ,
242
+ 'demo'
243
+ ] , {
244
+ cwd : getPath ( sample . dir )
245
+ } ) ;
177
246
178
- function testRequest ( ) {
179
- request ( 'http://localhost:8080' , function ( err , res , body ) {
180
- if ( body && body . indexOf ( sample . msg ) !== - 1 &&
181
- ( res . statusCode === 200 || res . statusCode === sample . code ) ) {
182
- success = true ;
183
- end ( ) ;
247
+ function finish ( err ) {
248
+ if ( ! calledDone ) {
249
+ calledDone = true ;
250
+ cb ( err ) ;
251
+ }
184
252
}
185
- } ) ;
253
+
254
+ proc . stderr . on ( 'data' , function ( data ) {
255
+ if ( shouldHide ( data ) ) {
256
+ return ;
257
+ }
258
+ console . log ( sample . projectId + ' stderr: ' + data ) ;
259
+ } ) ;
260
+ proc . stdout . on ( 'data' , function ( data ) {
261
+ if ( shouldHide ( data ) ) {
262
+ return ;
263
+ }
264
+ console . log ( sample . projectId + ' stdout: ' + data ) ;
265
+ } ) ;
266
+ proc . on ( 'error' , finish ) ;
267
+ proc . on ( 'exit' , function ( code ) {
268
+ if ( code !== 0 ) {
269
+ finish ( new Error ( sample . dir + ': failed to deploy!' ) ) ;
270
+ } else {
271
+ var url = 'http://' + sample . projectId + '.appspot.com' ;
272
+ var demoUrl = 'http://demo.' + sample . projectId + '.appspot.com' ;
273
+ async . waterfall ( [
274
+ function ( cb ) {
275
+ setTimeout ( cb , 10000 ) ;
276
+ } ,
277
+ function ( cb ) {
278
+ // Test "default" module
279
+ testRequest ( url , sample , cb ) ;
280
+ } ,
281
+ function ( result , cb ) {
282
+ if ( ! result ) {
283
+ cb ( new Error ( sample . dir + ': failed verification!' ) ) ;
284
+ } else {
285
+ cb ( ) ;
286
+ }
287
+ } ,
288
+ function ( cb ) {
289
+ // Test versioned url of "default" module
290
+ testRequest ( demoUrl , sample , cb ) ;
291
+ } ,
292
+ function ( result , cb ) {
293
+ if ( ! result ) {
294
+ cb ( new Error ( sample . dir + ': failed verification!' ) ) ;
295
+ } else {
296
+ cb ( ) ;
297
+ }
298
+ }
299
+ ] , finish ) ;
300
+ }
301
+ } ) ;
302
+ } ;
186
303
}
187
- } ) ;
304
+ return function ( cb ) { cb ( ) ; } ;
305
+ } ) , done ) ;
188
306
} ) ;
189
307
} ) ;
0 commit comments