Refactor tasks/test.js to be more modular.

This way the main functionality of the script can be reused in the
tasks/test-coverage.js script, which has to run the testsuite as well.
This commit is contained in:
Marc Jansen
2015-04-02 09:13:17 +02:00
parent 7c9795ba35
commit 6a9c8f36f7

View File

@@ -37,10 +37,11 @@ function listen(min, max, server, callback) {
}
/**
function runTests(includeCoverage, callback) {
/**
* Create the debug server and run tests.
*/
serve.createServer(function(err, server) {
serve.createServer(function(err, server) {
if (err) {
process.stderr.write(err.message + '\n');
process.exit(1);
@@ -51,24 +52,35 @@ serve.createServer(function(err, server) {
process.stderr.write('Server failed to start: ' + err.message + '\n');
process.exit(1);
}
var address = server.address();
var url = 'http://' + address.address + ':' + address.port;
var args = [
path.join(__dirname,
'../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee'),
path.join(
__dirname,
'../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee'
),
url + '/test/index.html'
];
if (process.argv.length > 2 && process.argv[2] === 'istanbul') {
if (includeCoverage) {
args.push('spec', '{"hooks": "' +
path.join(__dirname, '../test/phantom_hooks.js') + '"}');
}
var child = spawn(phantomjs.path, args, {stdio: 'inherit'});
child.on('exit', function(code) {
callback(code);
});
});
});
}
if (require.main === module) {
runTests(false, function(code){
process.exit(code);
});
});
}
module.exports = runTests;
});