|
| 1 | +#!/usr/bin/env node |
| 2 | +process.env.NODE_ENV = 'test'; |
| 3 | +require('../lib'); |
| 4 | + |
| 5 | +var fs = require('fs'); |
| 6 | +var Mocha = require('mocha'); |
| 7 | +var optimist = require('optimist'); |
| 8 | +var walk_dir = require('./support/walk_dir'); |
| 9 | + |
| 10 | +var argv = optimist |
| 11 | + .usage("Usage: $0 -t [types] --reporter [reporter] --timeout [timeout]") |
| 12 | + .default({types: 'unit,component', reporter: 'spec', timeout: 6000}) |
| 13 | + .describe('types', 'The types of tests to run, separated by commas. E.g., unit,component,acceptance') |
| 14 | + .describe('reporter', 'The mocha test reporter to use.') |
| 15 | + .describe('timeout', 'The mocha timeout to use per test (ms).') |
| 16 | + .boolean('help') |
| 17 | + .alias('types', 'T') |
| 18 | + .alias('timeout', 't') |
| 19 | + .alias('reporter', 'R') |
| 20 | + .alias('help', 'h') |
| 21 | + .argv; |
| 22 | + |
| 23 | +var mocha = new Mocha({timeout: argv.timeout, reporter: argv.reporter, ui: 'bdd'}); |
| 24 | + |
| 25 | +var valid_test_types = ['unit', 'functional', 'acceptance', 'integration']; |
| 26 | +var requested_types = argv.types.split(','); |
| 27 | +var types_to_use = []; |
| 28 | + |
| 29 | +valid_test_types.forEach(function (valid_test_type) { |
| 30 | + if (requested_types.indexOf(valid_test_type) !== -1) { |
| 31 | + types_to_use.push(valid_test_type); |
| 32 | + } |
| 33 | +}); |
| 34 | + |
| 35 | +if (argv.help || types_to_use.length === 0) { |
| 36 | + console.log('\n' + optimist.help()); |
| 37 | + process.exit(); |
| 38 | +} |
| 39 | + |
| 40 | +var is_valid_file = function (file) { |
| 41 | + for (var i = 0; i < types_to_use.length; i++) { |
| 42 | + var test_type = types_to_use[i]; |
| 43 | + var ext = test_type + ".js"; |
| 44 | + |
| 45 | + if (file.indexOf(ext) !== -1) { |
| 46 | + return true; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + return false; |
| 51 | +}; |
| 52 | + |
| 53 | +function run(cb) { |
| 54 | + walk_dir.walk('test', is_valid_file, function (err, files) { |
| 55 | + if (err) { return cb(err); } |
| 56 | + |
| 57 | + files.forEach(function (file) { |
| 58 | + mocha.addFile(file); |
| 59 | + }); |
| 60 | + |
| 61 | + cb(); |
| 62 | + }); |
| 63 | +} |
| 64 | + |
| 65 | +run(function (err) { |
| 66 | + mocha.run(function (failures) { |
| 67 | + process.exit(failures); |
| 68 | + }); |
| 69 | +}); |
0 commit comments