added saucelabs tests runner

This commit is contained in:
Vitaly Puzrin 2014-02-28 00:22:56 +04:00
parent 9af504523f
commit b9171721f9
6 changed files with 126 additions and 113 deletions

78
Gruntfile.js Normal file
View file

@ -0,0 +1,78 @@
'use strict';
module.exports = function(grunt) {
var browsers = [{
browserName: 'iphone',
platform: 'OS X 10.8',
version: '6'
}, {
browserName: 'android',
platform: 'Linux',
version: '4.0'
}, {
browserName: 'firefox',
platform: 'XP'
}, {
browserName: 'chrome',
platform: 'XP'
}, {
browserName: 'internet explorer',
platform: 'WIN8',
version: '10'
}, {
browserName: 'internet explorer',
platform: 'VISTA',
version: '9'
}, {
browserName: 'internet explorer',
platform: 'Windows 7',
version: '8'
}, {
browserName: 'internet explorer',
platform: 'XP',
version: '7'
}, {
browserName: 'opera',
platform: 'Windows 2008',
version: '12'
}, {
browserName: 'safari',
platform: 'OS X 10.8',
version: '6'
}];
grunt.initConfig({
connect: {
server: {
options: {
base: '',
port: 9999
}
}
},
'saucelabs-mocha': {
all: {
options: {
urls: ['http://127.0.0.1:9999/test/browser/test.html'],
tunnelTimeout: 5,
build: process.env.TRAVIS_JOB_ID,
concurrency: 3,
browsers: browsers,
testname: process.env.SAUCE_PROJ || 'mocha tests',
tags: ['master']
}
}
},
watch: {}
});
// Loading dependencies
for (var key in grunt.file.readJSON('package.json').devDependencies) {
if (key !== 'grunt' && key.indexOf('grunt') === 0) { grunt.loadNpmTasks(key); }
}
//grunt.registerTask('dev', ['connect', 'watch']);
grunt.registerTask('test', ['connect', 'saucelabs-mocha']);
};

View file

@ -32,7 +32,7 @@ test: lint
test-browser: lint
rm -f ./test/browser/pako.js
browserify -r ./ -s pako > test/browser/pako.js
@SAUCE_PROJ=${GITHUB_PROJ} test/browser/sauce-run.js
@SAUCE_PROJ=${GITHUB_PROJ} grunt test
cover:
rm -rf cover

View file

@ -27,8 +27,10 @@
"lodash": "2.4.1",
"async": "0.2.10",
"mocha-cloud": "*",
"mocha-cloud-grid-view": "*",
"term-canvas": "*"
"grunt": "~0.4.0",
"grunt-cli": "~0.1.6",
"grunt-saucelabs": "~4.0.2",
"grunt-contrib-connect": "~0.1.2",
"grunt-contrib-watch": "~0.2.0"
}
}

View file

@ -1,14 +0,0 @@
[
{ "browserName": "iphone", "platform": "OS X 10.8", "version": "6" },
{ "browserName": "android", "platform": "Linux", "version": "4.0" },
{ "browserName": "firefox", "platform": "XP" },
{ "browserName": "chrome", "platform": "XP" },
{ "browserName": "internet explorer", "platform": "WIN8", "version": "10" },
{ "browserName": "internet explorer", "platform": "VISTA", "version": "9" },
{ "browserName": "internet explorer", "platform": "Windows 7","version": "8" },
{ "browserName": "internet explorer", "platform": "XP", "version": "7" },
{ "browserName": "opera", "platform": "Windows 2008","version": "12" },
{ "browserName": "safari", "platform": "OS X 10.8", "version": "6" }
]

View file

@ -1,77 +0,0 @@
#!/usr/bin/env node
/* You have to setup 3 enviroment variables to run this script:
*
* SAUCE_PROJ - project name
* SAUCE_USER - saucelabs user name
* SAUCE_AUTH - saucelabs authorisation token
*/
'use strict';
var Cloud = require('mocha-cloud');
/* , Canvas = require('term-canvas')
, size = process.stdout.getWindowSize()
, GridView = require('mocha-cloud-grid-view');*/
/*if (!process.env.SAUCE_PROJ || !process.env.SAUCE_USER || !process.env.SAUCE_AUTH) {
console.err('You must set enviroment variables SAUCE_PROJ, SAUCE_USER and SAUCE_AUTH');
process.exit(1);
}*/
var cloud = new Cloud(process.env.SAUCE_PROJ, process.env.SAUCE_USER, process.env.SAUCE_AUTH);
// the browsers to test
var browsers = require('./browsers.json');
browsers.forEach(function(browser) {
cloud.browser(browser.browserName, browser.version, browser.platform);
});
// the local url to test
cloud.url('http://localhost:3000/test/browser/');
// setup
/*var canvas = new Canvas(size[0], size[1]);
var ctx = canvas.getContext('2d');
var grid = new GridView(cloud, ctx);
grid.size(canvas.width, canvas.height);
ctx.hideCursor();
// trap SIGINT
process.on('SIGINT', function(){
ctx.reset();
process.nextTick(function(){
process.exit();
});
});
// output failure messages
// once complete, and exit > 0
// accordingly
cloud.start(function(){
grid.showFailures();
setTimeout(function(){
ctx.showCursor();
process.exit(grid.totalFailures());
}, 100);
});*/
cloud.on('init', function(browser){
console.log(' init : %s %s', browser.browserName, browser.version);
});
cloud.on('start', function(browser){
console.log(' start : %s %s', browser.browserName, browser.version);
});
cloud.on('end', function(browser, res){
console.log(' end : %s %s : %d failures', browser.browserName, browser.version, res.failures);
});
cloud.start();

View file

@ -1,28 +1,52 @@
<html>
<head>
<title>pako tests</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/chai/chai.js"></script>
<script>
mocha.setup('bdd');
assert = chai.assert;
</script>
<script>
function assert(expr, msg) {
if (!expr) throw new Error(msg || 'failed');
}
</script>
<script src="./pako.js"></script>
<script src="./test.js"></script>
<script>
onload = function(){
var runner = mocha.run();
var failedTests = [];
runner.on('end', function(){
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
runner.on('fail', logFailure);
function logFailure(test, err){
var flattenTitles = function(test){
var titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
};
};
</script>
</head>
<body>
<div id="mocha"></div>
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/chai/chai.js"></script>
<script src="./pako.js"></script>
<script>
mocha.ui('bdd');
mocha.reporter('html');
assert = chai.assert;
</script>
<script src="test.js"></script>
<script>
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.run();
}
</script>
</body>
</html>