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