You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

12 years ago
#!/usr/bin/env node
process.env.NODE_ENV = 'test';
require('../index');
var Mocha = require('mocha');
var optimist = require('optimist');
var walk_dir = require('./support').walk_dir;
var argv = optimist
.usage("Usage: $0 -t [types] --reporter [reporter] --timeout [timeout]")['default'](
{types: 'unit,functional', reporter: 'spec', timeout: 6000})
12 years ago
.describe('types', 'The types of tests to run, separated by commas. E.g., unit,functional,acceptance')
.describe('reporter', 'The mocha test reporter to use.')
.describe('timeout', 'The mocha timeout to use per test (ms).')
.boolean('help')
.alias('types', 'T')
.alias('timeout', 't')
.alias('reporter', 'R')
.alias('help', 'h')
.argv;
var mocha = new Mocha({timeout: argv.timeout, reporter: argv.reporter, ui: 'bdd'});
var valid_test_types = ['unit', 'functional', 'acceptance', 'integration'];
var requested_types = argv.types.split(',');
var types_to_use = [];
10 years ago
valid_test_types.forEach(function(valid_test_type) {
12 years ago
if (requested_types.indexOf(valid_test_type) !== -1) {
types_to_use.push(valid_test_type);
}
});
if (argv.help || types_to_use.length === 0) {
console.log('\n' + optimist.help());
process.exit();
}
10 years ago
var is_valid_file = function(file) {
12 years ago
if (file.match(/buster/)) {
return false;
}
for (var i = 0; i < types_to_use.length; i++) {
var test_type = types_to_use[i];
var ext = test_type + ".js";
if (file.indexOf(ext) !== -1) {
return true;
}
}
return false;
};
function run(cb) {
10 years ago
walk_dir('test', is_valid_file, function(err, files) {
12 years ago
if (err) { return cb(err); }
10 years ago
files.forEach(function(file) {
12 years ago
mocha.addFile(file);
});
cb();
});
}
10 years ago
run(function(err) {
12 years ago
if (err) { throw err; }
10 years ago
mocha.run(function(failures) {
12 years ago
process.exit(failures);
});
});