Skip to content

Commit

Permalink
Add script runner for saucelabs
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Mar 16, 2015
1 parent 40da5ee commit 47fc7d5
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 196 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test: node_modules/ build lint
./script/test

saucelabs: build
node ./test/saucelabs.js
./script/saucelabs

travis: lint test saucelabs

Expand Down
11 changes: 11 additions & 0 deletions script/saucelabs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

port=8080

# Spin a test server in the background
node ./test/server.js $port &>/dev/null &
server_pid=$!
trap "kill $server_pid" INT EXIT

node ./test/saucelabs.js "http://localhost:$port/test/test.html"
138 changes: 0 additions & 138 deletions test/app.js

This file was deleted.

100 changes: 46 additions & 54 deletions test/saucelabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require('es6-promise');
var http = require('http');
var https = require('https');
var app = require('./app');

function fetchJSON(options, obj) {
var data = JSON.stringify(obj);
Expand Down Expand Up @@ -35,61 +34,54 @@ function wait(ms) {
});
}

var server = http.createServer(app);
server.on('listening', function() {
var port = server.address().port;
var url = 'http://localhost:'+port+'/test/test.html';

fetchJSON({
method: 'POST',
hostname: 'saucelabs.com',
path: '/rest/v1/' + process.env.SAUCE_USERNAME + '/js-tests',
headers: {},
auth: process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY
}, {
'build': process.env.TRAVIS_BUILD_NUMBER,
'tags': [process.env.TRAVIS_PULL_REQUEST, process.env.TRAVIS_BRANCH],
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'platforms': [[process.env.SAUCE_PLATFORM, process.env.SAUCE_BROWSER, process.env.SAUCE_VERSION]],
'url': url,
'framework': 'qunit'
}).then(function(obj) {
function check() {
return fetchJSON({
method: 'POST',
hostname: 'saucelabs.com',
path: '/rest/v1/' + process.env.SAUCE_USERNAME + '/js-tests/status',
headers: {},
auth: process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY
}, obj).then(function(obj) {
if (obj.completed === true) {
return obj;
} else {
return wait(2 * 1000).then(check);
}
});
}
return Promise.race([check(), timeout(180 * 1000)]);
}).then(function(obj) {
var test = obj['js tests'][0];
fetchJSON({
method: 'POST',
hostname: 'saucelabs.com',
path: '/rest/v1/' + process.env.SAUCE_USERNAME + '/js-tests',
headers: {},
auth: process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY
}, {
'build': process.env.TRAVIS_BUILD_NUMBER,
'tags': [process.env.TRAVIS_PULL_REQUEST, process.env.TRAVIS_BRANCH],
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'platforms': [[process.env.SAUCE_PLATFORM, process.env.SAUCE_BROWSER, process.env.SAUCE_VERSION]],
'url': process.argv[2],
'framework': 'qunit'
}).then(function(obj) {
function check() {
return fetchJSON({
method: 'POST',
hostname: 'saucelabs.com',
path: '/rest/v1/' + process.env.SAUCE_USERNAME + '/js-tests/status',
headers: {},
auth: process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY
}, obj).then(function(obj) {
if (obj.completed === true) {
return obj;
} else {
return wait(2 * 1000).then(check);
}
});
}
return Promise.race([check(), timeout(180 * 1000)]);
}).then(function(obj) {
var test = obj['js tests'][0];

console.log(test.url);
console.log(test.platform);
console.log(test.result);
console.log(test.url);
console.log(test.platform);
console.log(test.result);

var passed = test.result && (typeof test.result === 'object') &&
test.result.passed === test.result.total;
var passed = test.result && (typeof test.result === 'object') &&
test.result.passed === test.result.total;

if (!passed) {
throw 'tests failed';
}
}).then(function() {
server.close();
global.process.exit(0);
}, function(error) {
setImmediate(function() {
throw error;
});
if (!passed) {
throw 'tests failed';
}
}).then(function() {
server.close();
global.process.exit(0);
}, function(error) {
setImmediate(function() {
throw error;
});
});
server.listen(8080);
Loading

0 comments on commit 47fc7d5

Please sign in to comment.