1
+ /*eslint-env node*/
2
+ 'use strict' ;
1
3
var LIBS = {
4
+ Sauce : require ( 'sauce-tunnel' ) ,
5
+ http : require ( 'http' ) ,
6
+ serve : require ( 'serve-static' ) ,
7
+ final : require ( 'finalhandler' ) ,
2
8
async : require ( 'async' ) ,
3
9
child : require ( 'child_process' ) ,
4
10
fs : require ( 'fs' ) ,
5
11
path : require ( 'path' ) ,
6
12
util : require ( 'util' ) ,
7
13
wd : require ( 'wd' )
8
14
} ,
15
+
9
16
TEST_DIR = LIBS . path . resolve ( __dirname , 'test262' , 'pages' ) ,
10
17
BROWSER_CONCURRENCY = 3 ,
11
18
BROWSERS = [
@@ -54,15 +61,20 @@ var LIBS = {
54
61
{
55
62
browserName : "internet explorer" ,
56
63
version : "8" ,
57
- platform : "Windows 7"
64
+ platform : "Windows 7" ,
65
+ prerun : 'http://localhost:8000/tests/ie8fix.bat'
58
66
} ,
59
67
{
60
68
browserName : "safari" ,
61
69
version : "7" ,
62
70
platform : "OS X 10.9"
63
- } ,
71
+ }
64
72
] ,
65
73
74
+ tunnel = process . env . TRAVIS_BUILD_NUMBER ? null : new LIBS . Sauce ( process . env . SAUCE_USERNAME , process . env . SAUCE_ACCESS_KEY ) ,
75
+ serveStatic = LIBS . serve ( LIBS . path . resolve ( __dirname , '../' ) ) ,
76
+ testBaseURL = 'http://localhost:8000/tests/test262/pages/' ,
77
+
66
78
// A list of tests that ES3 environments can't pass, either because they
67
79
// use accessors or they test for behaviour achievable only in ES5 environments
68
80
es3blacklist = [
@@ -71,6 +83,10 @@ var LIBS = {
71
83
'12.2.1.html' , '12.3.3.html' , '12.3_b.html' , '12.3.2_TLT_2.html'
72
84
] ;
73
85
86
+ LIBS . http . createServer ( function ( req , res ) {
87
+ var done = LIBS . final ( req , res ) ;
88
+ serveStatic ( req , res , done ) ;
89
+ } ) . listen ( 8000 ) ;
74
90
75
91
function listTests ( ) {
76
92
var tests = [ ] ,
@@ -97,190 +113,6 @@ function listTests() {
97
113
return tests ;
98
114
}
99
115
100
-
101
- function runCommand ( command , done ) {
102
- console . log ( '--COMMAND--' , command . join ( ' ' ) ) ;
103
- var cmd = command . shift ( ) ,
104
- stdout = '' ,
105
- stderr = '' ,
106
- err ,
107
- pid ;
108
- pid = LIBS . child . spawn ( cmd , command , {
109
- cwd : process . cwd ( ) ,
110
- env : process . env
111
- } ) ;
112
- pid . stdout . on ( 'data' , function ( data ) {
113
- stdout += data ;
114
- } ) ;
115
- pid . stderr . on ( 'data' , function ( data ) {
116
- stderr += data ;
117
- } ) ;
118
- pid . on ( 'exit' , function ( code ) {
119
- done ( err , code , stdout , stderr ) ;
120
- } ) ;
121
- pid . on ( 'error' , function ( err ) {
122
- done ( err , err . code , stdout , stderr ) ;
123
- } ) ;
124
- pid . on ( 'uncaughtException' , function ( err ) {
125
- done ( err , err . code || 1 , stdout , stderr ) ;
126
- } ) ;
127
- }
128
-
129
-
130
- function gitDetailsFromTravis ( state , done ) {
131
- if ( process . env . TRAVIS ) {
132
- // travis makes this information easy to get
133
- state . git . shasum = process . env . TRAVIS_COMMIT ;
134
- var parts = process . env . TRAVIS_REPO_SLUG . split ( '/' ) ;
135
- state . git . user = parts [ 0 ] ;
136
- state . git . repo = parts [ 1 ] ;
137
- state . git . rawURL = 'https://rawgithub.com/' + state . git . user + '/' + state . git . repo + '/' + state . git . shasum + '/tests/test262/pages/' ;
138
- done ( new Error ( 'FOUND' ) ) ;
139
- return ;
140
- }
141
- done ( ) ;
142
- }
143
-
144
-
145
- function gitDetailsFromGit ( state , done ) {
146
- LIBS . async . series ( [
147
- function ( taskDone ) {
148
- runCommand ( [ 'git' , 'rev-parse' , 'HEAD' ] , function ( err , code , stdout , stderr ) {
149
- if ( err ) {
150
- taskDone ( err ) ;
151
- return ;
152
- }
153
- state . git . shasum = stdout . trim ( ) ;
154
- if ( ! state . git . shasum ) {
155
- taskDone ( new Error ( "failed to find current commit" ) ) ;
156
- return ;
157
- }
158
- taskDone ( ) ;
159
- } ) ;
160
- } ,
161
- function ( taskDone ) {
162
- runCommand ( [ 'git' , 'branch' , '--all' , '--contains' , state . git . shasum ] , function ( err , code , stdout , stderr ) {
163
- var matches ;
164
- if ( err ) {
165
- taskDone ( err ) ;
166
- return ;
167
- }
168
- matches = stdout . match ( / r e m o t e s \/ ( [ ^ \/ ] + ) \/ ( [ ^ \/ \n \s ] + ) $ / m) ;
169
- if ( matches ) {
170
- state . git . remote = matches [ 1 ] ;
171
- state . git . branch = matches [ 2 ] ;
172
- taskDone ( ) ;
173
- return ;
174
- }
175
- taskDone ( new Error ( 'failed to find relevant remote for ' + state . git . shasum ) ) ;
176
- } ) ;
177
- } ,
178
- function ( taskDone ) {
179
- runCommand ( [ 'git' , 'config' , '--get' , [ 'remote' , state . git . remote , 'url' ] . join ( '.' ) ] , function ( err , code , stdout , stderr ) {
180
- var matches ;
181
- if ( err ) {
182
- taskDone ( err ) ;
183
- return ;
184
- }
185
- matches = stdout . trim ( ) . match ( / ( [ ^ : \/ ] + ) \/ ( [ ^ \/ ] + ) \. g i t $ / ) ;
186
- if ( matches ) {
187
- state . git . user = matches [ 1 ] ;
188
- state . git . repo = matches [ 2 ] ;
189
- state . git . rawURL = 'https://rawgithub.com/' + state . git . user + '/' + state . git . repo + '/' + state . git . shasum + '/tests/test262/pages/' ;
190
- taskDone ( ) ;
191
- return ;
192
- }
193
- taskDone ( new Error ( 'failed to find repository URL for remote ' + state . git . remote ) ) ;
194
- } ) ;
195
- }
196
- ] , function ( err ) {
197
- if ( err ) {
198
- console . log ( err . message ) ;
199
- done ( ) ;
200
- }
201
- else {
202
- done ( new Error ( 'FOUND' ) ) ;
203
- }
204
- } ) ;
205
- }
206
-
207
-
208
- function gitDetailsFromFilesystem ( state , done ) {
209
- var gitDir = LIBS . path . resolve ( process . cwd ( ) , '..' , '.git' ) ,
210
- config ;
211
-
212
- function readRef ( ref ) {
213
- /*jshint boss:true*/
214
- var path = LIBS . path . resolve ( gitDir , ref ) ,
215
- contents = LIBS . fs . readFileSync ( path ) . toString ( ) ,
216
- matches ;
217
-
218
- while ( matches = contents . match ( / r e f : ( \S + ) / ) ) {
219
- path = LIBS . path . resolve ( gitDir , matches [ 1 ] ) ;
220
- contents = LIBS . fs . readFileSync ( path ) . toString ( ) ;
221
- }
222
- return contents . trim ( ) ;
223
- }
224
-
225
- state . git . shasum = readRef ( 'HEAD' ) ;
226
- if ( ! state . git . shasum ) {
227
- console . log ( "failed to find current commit" ) ;
228
- done ( ) ;
229
- return ;
230
- }
231
-
232
- LIBS . fs . readdirSync ( LIBS . path . resolve ( gitDir , 'refs' , 'remotes' ) ) . forEach ( function ( remoteDir ) {
233
- LIBS . fs . readdirSync ( LIBS . path . resolve ( gitDir , 'refs' , 'remotes' , remoteDir ) ) . forEach ( function ( branchFile ) {
234
- var contents = readRef ( LIBS . path . join ( 'refs' , 'remotes' , remoteDir , branchFile ) ) ;
235
- if ( contents === state . git . shasum ) {
236
- state . git . remote = remoteDir ;
237
- state . git . branch = branchFile ;
238
- }
239
- } ) ;
240
- } ) ;
241
- if ( ! state . git . remote ) {
242
- console . log ( 'failed to find relevant remote for ' + state . git . shasum ) ;
243
- done ( ) ;
244
- return ;
245
- }
246
-
247
- config = LIBS . fs . readFileSync ( LIBS . path . resolve ( gitDir , 'config' ) ) . toString ( ) ;
248
- config . split ( '\n[' ) . forEach ( function ( conf ) {
249
- var matches = conf . match ( / ^ r e m o t e " ( [ ^ " ] + ) " \] ( .| \n ) * u r l \s * = \s * \S + g i t h u b \. c o m [: \/ ] ( [ ^ \/ ] * ) \/ ( .+ ) \. g i t / m) ;
250
- if ( matches && ( matches [ 1 ] === state . git . remote ) ) {
251
- state . git . user = matches [ 3 ] ;
252
- state . git . repo = matches [ 4 ] ;
253
- state . git . rawURL = 'https://rawgithub.com/' + state . git . user + '/' + state . git . repo + '/' + state . git . shasum + '/tests/test262/pages/' ;
254
- }
255
- } ) ;
256
- if ( ! state . git . rawURL ) {
257
- console . log ( 'failed to find repository URL for remote ' + state . git . remote ) ;
258
- done ( ) ;
259
- return ;
260
- }
261
-
262
- done ( new Error ( 'FOUND' ) ) ;
263
- }
264
-
265
-
266
- function calculateGitDetails ( state , done ) {
267
- state . git = { } ;
268
- LIBS . async . series ( [
269
- gitDetailsFromTravis . bind ( null , state ) ,
270
- gitDetailsFromGit . bind ( null , state ) ,
271
- gitDetailsFromFilesystem . bind ( null , state )
272
- ] , function ( err ) {
273
- console . log ( JSON . stringify ( state . git , null , 4 ) ) ;
274
- if ( err && err . message === 'FOUND' ) {
275
- done ( ) ;
276
- }
277
- else {
278
- done ( new Error ( 'failed to find git details' ) ) ;
279
- }
280
- } ) ;
281
- }
282
-
283
-
284
116
function runTestsInBrowser ( state , browserConfig , done ) {
285
117
var tasks = [ ] ,
286
118
caps = { } ,
@@ -305,16 +137,12 @@ function runTestsInBrowser(state, browserConfig, done) {
305
137
user : state . sauce . username ,
306
138
pwd : state . sauce . access_key
307
139
} ;
140
+
308
141
if ( process . env . TRAVIS ) {
309
142
// "sauce connect" travis addon
310
143
// http://about.travis-ci.org/docs/user/gui-and-headless-browsers/#Using-Sauce-Labs
311
144
sauceConfig . hostname = 'localhost' ;
312
145
sauceConfig . port = 4445 ;
313
- sauceConfig [ 'custom-data' ] = {
314
- gituser : state . git . user ,
315
- gitrepo : state . git . repo ,
316
- commit : state . git . shasum
317
- } ;
318
146
sauceConfig [ 'record-video' ] = false ;
319
147
}
320
148
browser = LIBS . wd . remote ( sauceConfig ) ;
@@ -324,7 +152,7 @@ function runTestsInBrowser(state, browserConfig, done) {
324
152
// for each page, get and test page
325
153
state . tests . forEach ( function ( test ) {
326
154
tasks . push ( function ( taskDone ) {
327
- var url = state . git . rawURL + test ,
155
+ var url = testBaseURL + test ,
328
156
ie8 = browserConfig . browserName === 'internet explorer' && browserConfig . version === '8' ;
329
157
330
158
//- Skip impassable tests in IE 8
@@ -458,7 +286,10 @@ function runTests(state, done) {
458
286
}
459
287
460
288
461
- function main ( ) {
289
+ function main ( tunnelReady ) {
290
+ if ( ! tunnelReady ) {
291
+ throw new Error ( 'Could not start Sauce Tunnel' ) ;
292
+ }
462
293
var state = { } ;
463
294
state . tests = listTests ( ) ;
464
295
state . sauce = {
@@ -474,8 +305,8 @@ function main() {
474
305
state . capabilities = {
475
306
tags : [ ]
476
307
} ;
308
+ state . capabilities [ 'tunnel-identifier' ] = process . env . TRAVIS_JOB_NUMBER || tunnel . identifier ;
477
309
if ( process . env . TRAVIS_JOB_NUMBER ) {
478
- state . capabilities [ 'tunnel-identifier' ] = process . env . TRAVIS_JOB_NUMBER ;
479
310
// we only need one of these to run on travis
480
311
if ( '.1' !== process . env . TRAVIS_JOB_NUMBER . substr ( - 2 ) ) {
481
312
console . log ( 'NOOP -- only running on "first" (.1) travis job' ) ;
@@ -489,10 +320,10 @@ function main() {
489
320
console . log ( JSON . stringify ( state . capabilities , null , 4 ) ) ;
490
321
491
322
console . log ( '================================================ START' ) ;
492
- LIBS . async . series ( [
493
- calculateGitDetails . bind ( null , state ) ,
494
- runTests . bind ( null , state )
495
- ] , function ( err ) {
323
+ runTests ( state , function ( err ) {
324
+ if ( tunnel ) {
325
+ tunnel . stop ( function ( ) { } ) ;
326
+ }
496
327
console . log ( '================================================ DONE' ) ;
497
328
if ( err ) {
498
329
console . error ( err ) ;
@@ -502,8 +333,16 @@ function main() {
502
333
if ( state . results . failCount ) {
503
334
process . exit ( 1 ) ;
504
335
}
336
+
337
+ process . exit ( 0 ) ;
505
338
} ) ;
506
339
}
507
- main ( ) ;
508
-
509
340
341
+ if ( tunnel ) {
342
+ console . log ( 'Starting SauceTunnel...' ) ;
343
+ tunnel . start ( main ) ;
344
+ tunnel . proc . stdout . pipe ( process . stdout ) ;
345
+ }
346
+ else {
347
+ main ( true ) ;
348
+ }
0 commit comments