Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit fed0571

Browse files
author
Andy Earnshaw
committed
Run sauce tests locally, prerun bat for ie8
1 parent 1fced3d commit fed0571

File tree

3 files changed

+43
-200
lines changed

3 files changed

+43
-200
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"devDependencies": {
1111
"async": "^0.9.0",
12+
"finalhandler": "^0.4.0",
1213
"glob": "^5.0.3",
1314
"grunt": "^0.4.5",
1415
"grunt-bundle-jsnext-lib": "^0.2.1",
@@ -23,6 +24,8 @@
2324
"grunt-zip": "^0.16.2",
2425
"jshint": "^2.5.5",
2526
"object.assign": "^1.1.1",
27+
"sauce-tunnel": "^2.2.3",
28+
"serve-static": "^1.10.0",
2629
"wd": "^0.3.6"
2730
},
2831
"scripts": {

tests/ie8fix.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles" /v "MaxScriptStatements" /t REG_DWORD /d 0xFFFFFFFF /f

tests/saucelabs.js

+39-200
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
/*eslint-env node*/
2+
'use strict';
13
var LIBS = {
4+
Sauce: require('sauce-tunnel'),
5+
http: require('http'),
6+
serve: require('serve-static'),
7+
final: require('finalhandler'),
28
async: require('async'),
39
child: require('child_process'),
410
fs: require('fs'),
511
path: require('path'),
612
util: require('util'),
713
wd: require('wd')
814
},
15+
916
TEST_DIR = LIBS.path.resolve(__dirname, 'test262', 'pages'),
1017
BROWSER_CONCURRENCY = 3,
1118
BROWSERS = [
@@ -54,15 +61,20 @@ var LIBS = {
5461
{
5562
browserName: "internet explorer",
5663
version: "8",
57-
platform: "Windows 7"
64+
platform: "Windows 7",
65+
prerun: 'http://localhost:8000/tests/ie8fix.bat'
5866
},
5967
{
6068
browserName: "safari",
6169
version: "7",
6270
platform: "OS X 10.9"
63-
},
71+
}
6472
],
6573

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+
6678
// A list of tests that ES3 environments can't pass, either because they
6779
// use accessors or they test for behaviour achievable only in ES5 environments
6880
es3blacklist = [
@@ -71,6 +83,10 @@ var LIBS = {
7183
'12.2.1.html', '12.3.3.html', '12.3_b.html', '12.3.2_TLT_2.html'
7284
];
7385

86+
LIBS.http.createServer(function(req, res) {
87+
var done = LIBS.final(req, res);
88+
serveStatic(req, res, done);
89+
}).listen(8000);
7490

7591
function listTests() {
7692
var tests = [],
@@ -97,190 +113,6 @@ function listTests() {
97113
return tests;
98114
}
99115

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(/remotes\/([^\/]+)\/([^\/\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(/([^:\/]+)\/([^\/]+)\.git$/);
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(/ref: (\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(/^remote "([^"]+)"\](.|\n)*url\s*=\s*\S+github\.com[:\/]([^\/]*)\/(.+)\.git/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-
284116
function runTestsInBrowser(state, browserConfig, done) {
285117
var tasks = [],
286118
caps = {},
@@ -305,16 +137,12 @@ function runTestsInBrowser(state, browserConfig, done) {
305137
user: state.sauce.username,
306138
pwd: state.sauce.access_key
307139
};
140+
308141
if (process.env.TRAVIS) {
309142
// "sauce connect" travis addon
310143
// http://about.travis-ci.org/docs/user/gui-and-headless-browsers/#Using-Sauce-Labs
311144
sauceConfig.hostname = 'localhost';
312145
sauceConfig.port = 4445;
313-
sauceConfig['custom-data'] = {
314-
gituser: state.git.user,
315-
gitrepo: state.git.repo,
316-
commit: state.git.shasum
317-
};
318146
sauceConfig['record-video'] = false;
319147
}
320148
browser = LIBS.wd.remote(sauceConfig);
@@ -324,7 +152,7 @@ function runTestsInBrowser(state, browserConfig, done) {
324152
// for each page, get and test page
325153
state.tests.forEach(function(test) {
326154
tasks.push(function(taskDone) {
327-
var url = state.git.rawURL + test,
155+
var url = testBaseURL + test,
328156
ie8 = browserConfig.browserName === 'internet explorer' && browserConfig.version === '8';
329157

330158
//- Skip impassable tests in IE 8
@@ -458,7 +286,10 @@ function runTests(state, done) {
458286
}
459287

460288

461-
function main() {
289+
function main(tunnelReady) {
290+
if (!tunnelReady) {
291+
throw new Error('Could not start Sauce Tunnel');
292+
}
462293
var state = {};
463294
state.tests = listTests();
464295
state.sauce = {
@@ -474,8 +305,8 @@ function main() {
474305
state.capabilities = {
475306
tags: []
476307
};
308+
state.capabilities['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER || tunnel.identifier;
477309
if (process.env.TRAVIS_JOB_NUMBER) {
478-
state.capabilities['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER;
479310
// we only need one of these to run on travis
480311
if ('.1' !== process.env.TRAVIS_JOB_NUMBER.substr(-2)) {
481312
console.log('NOOP -- only running on "first" (.1) travis job');
@@ -489,10 +320,10 @@ function main() {
489320
console.log(JSON.stringify(state.capabilities, null, 4));
490321

491322
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+
}
496327
console.log('================================================ DONE');
497328
if (err) {
498329
console.error(err);
@@ -502,8 +333,16 @@ function main() {
502333
if (state.results.failCount) {
503334
process.exit(1);
504335
}
336+
337+
process.exit(0);
505338
});
506339
}
507-
main();
508-
509340

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

Comments
 (0)