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,47 @@ 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
+ exec ( 'npm run deploy' , {
219
+ cwd : getPath ( sample . dir ) ,
220
+ maxBuffer : 1000000
221
+ } , function ( err , stdout , stderr ) {
222
+ console . log ( stdout ) ;
223
+ console . log ( stderr ) ;
224
+ if ( err ) {
225
+ return cb ( err ) ;
226
+ } else {
227
+ var url = 'http://' + sample . projectId + '.appspot.com' ;
228
+ return testRequest ( url , sample , cb ) ;
229
+ }
230
+ } ) ;
231
+ } ;
232
+ }
233
+ return function ( cb ) { cb ( ) ; } ;
234
+ } ) , done ) ;
235
+ } ) ;
189
236
} ) ;
0 commit comments