14
14
'use strict' ;
15
15
16
16
var spawn = require ( 'child_process' ) . spawn ;
17
+ var exec = require ( 'child_process' ) . exec ;
17
18
var request = require ( 'request' ) ;
19
+ var async = require ( 'async' ) ;
18
20
19
21
var cwd = process . cwd ( ) ;
20
22
@@ -25,6 +27,7 @@ function getPath(dir) {
25
27
var sampleTests = [
26
28
{
27
29
dir : 'express' ,
30
+ projectId : 'express-demo' ,
28
31
cmd : 'node' ,
29
32
arg1 : './bin/www' ,
30
33
msg : 'Hello World! Express.js on Google App Engine.'
@@ -93,6 +96,27 @@ 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
+
96
120
describe ( 'appengine/' , function ( ) {
97
121
sampleTests . forEach ( function ( sample ) {
98
122
it ( sample . dir + ': dependencies should install' , function ( done ) {
@@ -166,24 +190,68 @@ describe('appengine/', function () {
166
190
}
167
191
} ) ;
168
192
169
- timeoutId = setTimeout ( end , 5000 ) ;
170
- intervalId = setInterval ( testRequest , 1000 ) ;
171
-
172
- function end ( ) {
173
- clearTimeout ( timeoutId ) ;
174
- clearInterval ( intervalId ) ;
175
- proc . kill ( 'SIGKILL' ) ;
176
- }
177
-
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 ( ) ;
193
+ timeoutId = setTimeout ( function ( ) {
194
+ end ( timeoutId , intervalId , proc ) ;
195
+ } , 5000 ) ;
196
+ intervalId = setInterval ( function ( ) {
197
+ testRequest ( 'http://localhost:8080' , sample , function ( err , _success ) {
198
+ if ( err ) {
199
+ console . log ( err ) ;
200
+ } else {
201
+ success = _success ;
184
202
}
203
+ end ( timeoutId , intervalId , proc ) ;
185
204
} ) ;
186
- }
205
+ } , 1000 ) ;
187
206
} ) ;
188
207
} ) ;
208
+
209
+ if ( ! process . env . TRAVIS ) {
210
+ return ;
211
+ }
212
+
213
+ it ( 'should deploy all samples' , function ( done ) {
214
+ this . timeout ( 10 * 60 * 1000 ) ; // 10 minutes
215
+ async . parallel ( sampleTests . map ( function ( sample ) {
216
+ if ( sample . projectId ) {
217
+ return function ( cb ) {
218
+ var calledDone = false ;
219
+ var timeoutId ;
220
+ var intervalId ;
221
+ var proc = spawn ( 'npm' , [ 'run' , 'deploy' ] , {
222
+ cwd : getPath ( sample . dir )
223
+ } ) ;
224
+
225
+ proc . stderr . on ( 'data' , function ( data ) {
226
+ console . log ( sample . projectId + ' stderr: ' + data ) ;
227
+ } ) ;
228
+ proc . stdout . on ( 'data' , function ( data ) {
229
+ console . log ( sample . projectId + ' stdout: ' + data ) ;
230
+ } ) ;
231
+ proc . on ( 'error' , function ( err ) {
232
+ if ( ! calledDone ) {
233
+ calledDone = true ;
234
+ done ( err ) ;
235
+ }
236
+ } ) ;
237
+ proc . on ( 'exit' , function ( code , signal ) {
238
+ var url = 'http://' + sample . projectId + '.appspot.com' ;
239
+ return testRequest ( url , sample , function ( err , result ) {
240
+ if ( err ) {
241
+ console . log ( err ) ;
242
+ }
243
+ if ( ! calledDone ) {
244
+ calledDone = true ;
245
+ if ( ! err && ! result ) {
246
+ err = new Error ( sample . dir + ': failed verification!' ) ;
247
+ }
248
+ done ( err , result ) ;
249
+ }
250
+ } ) ;
251
+ } ) ;
252
+ } ;
253
+ }
254
+ return function ( cb ) { cb ( ) ; } ;
255
+ } ) , done ) ;
256
+ } ) ;
189
257
} ) ;
0 commit comments