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:
+37
-25
@@ -37,38 +37,50 @@ function listen(min, max, server, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
function runTests(includeCoverage, callback) {
|
||||||
* Create the debug server and run tests.
|
/**
|
||||||
*/
|
* Create the debug server and run tests.
|
||||||
serve.createServer(function(err, server) {
|
*/
|
||||||
if (err) {
|
serve.createServer(function(err, server) {
|
||||||
process.stderr.write(err.message + '\n');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
listen(3001, 3005, server, function(err) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
process.stderr.write('Server failed to start: ' + err.message + '\n');
|
process.stderr.write(err.message + '\n');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = server.address();
|
listen(3001, 3005, server, function(err) {
|
||||||
var url = 'http://' + address.address + ':' + address.port;
|
if (err) {
|
||||||
var args = [
|
process.stderr.write('Server failed to start: ' + err.message + '\n');
|
||||||
path.join(__dirname,
|
process.exit(1);
|
||||||
'../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee'),
|
}
|
||||||
url + '/test/index.html'
|
var address = server.address();
|
||||||
];
|
var url = 'http://' + address.address + ':' + address.port;
|
||||||
|
var args = [
|
||||||
|
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": "' +
|
args.push('spec', '{"hooks": "' +
|
||||||
path.join(__dirname, '../test/phantom_hooks.js') + '"}');
|
path.join(__dirname, '../test/phantom_hooks.js') + '"}');
|
||||||
}
|
}
|
||||||
|
|
||||||
var child = spawn(phantomjs.path, args, {stdio: 'inherit'});
|
var child = spawn(phantomjs.path, args, {stdio: 'inherit'});
|
||||||
child.on('exit', function(code) {
|
child.on('exit', function(code) {
|
||||||
process.exit(code);
|
callback(code);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
runTests(false, function(code){
|
||||||
|
process.exit(code);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = runTests;
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user