Created
January 11, 2012 21:29
-
-
Save gcoop/1596848 to your computer and use it in GitHub Desktop.
PHPUnit/Selenium test suite runner. Runs single test suite on multiple browser and devices async.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Lighweight node app that will run phpunit tests async. The concept is to start the app with a environment flag and | |
* a CSV of browsers. App will then spawn child processes for each browser running your phpunit/selenium test suite | |
* with that browser and env flag passed. The result is a single test suite run concurrently on multiple browsers and | |
* devices with a single win/fail result from the node.js app. | |
*/ | |
// Verify arguments. | |
if (process.argv.length < 4) { | |
throw new Error("Usage: node batch-runner.js DEVELOPMENT Chrome,IE6,IE7"); | |
} | |
console.log("Going to run tests async, don't expect test output untill they've all finished so we can group by browser."); | |
var env = process.argv[2], | |
browsers = process.argv[3].split(","), | |
util = require('util'), | |
spawn = require('child_process').spawn, | |
totalSuites = browsers.length, | |
completedSuites = 0, | |
overallResult = 0; // OK | |
var completeSuite = function (browserName, code) { | |
console.log("Completed Browser "+browserName+": "+(code == 0 ? "\033[1;92mWIN\033[0m" : "\033[1;31mFAIL\033[0m")); | |
if (code != 0) { | |
overallResult = code; | |
} | |
completedSuites++; | |
if (completedSuites == totalSuites) { | |
process.exit(overallResult); | |
} | |
}; | |
browsers.forEach(function (v, i) { | |
console.log("Start running tests on "+v+"..."); | |
var runner = spawn('phpunit', ['tests.php', '--env', env, '--browser', v]), | |
log = []; | |
runner.stdout.on('data', function (data) { | |
log.push(data.toString()); | |
}); | |
runner.stderr.on('data', function (data) { | |
console.log('stderr: ' + data); | |
}); | |
runner.on('exit', function (code) { | |
console.log("\nTest report for "+v); | |
console.log(log.join("")); | |
completeSuite(v, code); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment