kocha
Version:
Modern, simpler Mocha clone, no globals, lint friendly
78 lines (59 loc) • 2.91 kB
JavaScript
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var select = require('action-selector').select;
var pkg = require('../package'
/**
* The command line interface.
*
*/
);
var Cli = function () {
function Cli() {
_classCallCheck(this, Cli);
}
_createClass(Cli, [{
key: 'main',
/**
* The entry point of cli.
* @param {object} argv The command line options parsed by minimist
*/
value: function main(argv) {
var _this = this;
this.argv = argv;
var version = argv.version;
var help = argv.help;
select(this, { version: version, help: help, run: true }).on('action', function (action) {
return action.call(_this);
});
}
/**
* Shows the help message.
*/
}, {
key: 'action:help',
value: function actionHelp() {
this['action:version']();
console.log('\nUsage: ' + pkg.name + ' [options] <file[, ...files]>\n\nOptions:\n -h, --help Shows the help message\n -v, --version Shows the version number\n -r, --require <name> Requires the given module e.g. --require babel-register\n -c, --config <path> Specify the config file path e.g. --config kocha.e2e.config.js\n -t, --timeout <ms> Sets the test-case timeout in milliseconds. Default is 2000.\n\nExamples:\n kocha test/ Runs all the tests under test/.\n\n kocha "src{/,**/}__tests__/**/*.js"\n Runs tests under the directory pattern src/**/__tests__/.\n\n kocha --require babel-register --require babel-polyfill test/\n Runs tests under test/ using babel and babel-polyfill.\n\n kocha --require coffee-script/register "test/**/*.coffee"\n Runs coffeescript tests under test/.\n');
}
/**
* Shows the version number.
*/
}, {
key: 'action:version',
value: function actionVersion() {
console.log(pkg.name + '@' + pkg.version);
}
/**
* Runs the tests.
*/
}, {
key: 'action:run',
value: function actionRun() {
this['action:version']();
require('./actions/run')(this.argv);
}
}]);
return Cli;
}();
module.exports = Cli;
;