| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = undefined;
- var _extends2 = require('babel-runtime/helpers/extends');
- var _extends3 = _interopRequireDefault(_extends2);
- var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
- var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
- var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
- var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
- var _createClass2 = require('babel-runtime/helpers/createClass');
- var _createClass3 = _interopRequireDefault(_createClass2);
- require('nodent-runtime');
- var _TestRunner = require('./runner/TestRunner');
- var _TestRunner2 = _interopRequireDefault(_TestRunner);
- var _testRunnerReporter = require('./runner/testRunnerReporter');
- var _testRunnerReporter2 = _interopRequireDefault(_testRunnerReporter);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- var MochaWebpack = function () {
- function MochaWebpack() {
- (0, _classCallCheck3.default)(this, MochaWebpack);
- this.entries = [];
- this.includes = [];
- this.options = {
- cwd: process.cwd(),
- webpackConfig: {},
- bail: false,
- reporter: 'spec',
- reporterOptions: {},
- ui: 'bdd',
- invert: false,
- ignoreLeaks: true,
- fullStackTrace: false,
- useInlineDiffs: false,
- timeout: 2000,
- slow: 75,
- asyncOnly: false,
- delay: false,
- interactive: !!process.stdout.isTTY,
- quiet: false
- };
- }
- /**
- * Files to run test against
- *
- * @private
- */
- /**
- * Files to include into the bundle
- *
- * @private
- */
- /**
- * Options
- *
- * @private
- */
- (0, _createClass3.default)(MochaWebpack, [{
- key: 'addEntry',
- /**
- * Add file run test against
- *
- * @public
- * @param {string} file file or glob
- * @return {MochaWebpack}
- */
- value: function addEntry(file) {
- this.entries = [].concat((0, _toConsumableArray3.default)(this.entries), [file]);
- return this;
- }
- /**
- * Add file to include into the test bundle
- *
- * @public
- * @param {string} file absolute path to module
- * @return {MochaWebpack}
- */
- }, {
- key: 'addInclude',
- value: function addInclude(file) {
- this.includes = [].concat((0, _toConsumableArray3.default)(this.includes), [file]);
- return this;
- }
- /**
- * Sets the current working directory
- *
- * @public
- * @param {string} cwd absolute working directory path
- * @return {MochaWebpack}
- */
- }, {
- key: 'cwd',
- value: function (_cwd) {
- function cwd(_x) {
- return _cwd.apply(this, arguments);
- }
- cwd.toString = function () {
- return _cwd.toString();
- };
- return cwd;
- }(function (cwd) {
- this.options = (0, _extends3.default)({}, this.options, {
- cwd: cwd
- });
- return this;
- })
- /**
- * Sets the webpack config
- *
- * @public
- * @param {Object} config webpack config
- * @return {MochaWebpack}
- */
- }, {
- key: 'webpackConfig',
- value: function webpackConfig() {
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- this.options = (0, _extends3.default)({}, this.options, {
- webpackConfig: config
- });
- return this;
- }
- /**
- * Enable or disable bailing on the first failure.
- *
- * @public
- * @param {boolean} [bail]
- * @return {MochaWebpack}
- */
- }, {
- key: 'bail',
- value: function (_bail) {
- function bail() {
- return _bail.apply(this, arguments);
- }
- bail.toString = function () {
- return _bail.toString();
- };
- return bail;
- }(function () {
- var bail = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
- this.options = (0, _extends3.default)({}, this.options, {
- bail: bail
- });
- return this;
- })
- /**
- * Set reporter to `reporter`, defaults to "spec".
- *
- * @param {string|Function} reporter name or constructor
- * @param {Object} reporterOptions optional options
- * @return {MochaWebpack}
- */
- }, {
- key: 'reporter',
- value: function (_reporter) {
- function reporter(_x2, _x3) {
- return _reporter.apply(this, arguments);
- }
- reporter.toString = function () {
- return _reporter.toString();
- };
- return reporter;
- }(function (reporter, reporterOptions) {
- this.options = (0, _extends3.default)({}, this.options, {
- reporter: reporter,
- reporterOptions: reporterOptions
- });
- return this;
- })
- /**
- * Set test UI, defaults to "bdd".
- *
- * @public
- * @param {string} ui bdd/tdd
- * @return {MochaWebpack}
- */
- }, {
- key: 'ui',
- value: function (_ui) {
- function ui(_x4) {
- return _ui.apply(this, arguments);
- }
- ui.toString = function () {
- return _ui.toString();
- };
- return ui;
- }(function (ui) {
- this.options = (0, _extends3.default)({}, this.options, {
- ui: ui
- });
- return this;
- })
- /**
- * Only run tests containing <string>
- *
- * @public
- * @param {string} str
- * @return {MochaWebpack}
- */
- }, {
- key: 'fgrep',
- value: function fgrep(str) {
- this.options = (0, _extends3.default)({}, this.options, {
- fgrep: str
- });
- return this;
- }
- /**
- * Only run tests matching <pattern>
- *
- * @public
- * @param {string|RegExp} pattern
- * @return {MochaWebpack}
- */
- }, {
- key: 'grep',
- value: function grep(pattern) {
- this.options = (0, _extends3.default)({}, this.options, {
- grep: pattern
- });
- return this;
- }
- /**
- * Invert `.grep()` matches.
- *
- * @public
- * @return {MochaWebpack}
- */
- }, {
- key: 'invert',
- value: function invert() {
- this.options = (0, _extends3.default)({}, this.options, {
- invert: true
- });
- return this;
- }
- /**
- * Ignore global leaks.
- *
- * @public
- * @param {boolean} ignore
- * @return {MochaWebpack}
- */
- }, {
- key: 'ignoreLeaks',
- value: function ignoreLeaks(ignore) {
- this.options = (0, _extends3.default)({}, this.options, {
- ignoreLeaks: ignore
- });
- return this;
- }
- /**
- * Display long stack-trace on failing
- *
- * @public
- * @return {MochaWebpack}
- */
- }, {
- key: 'fullStackTrace',
- value: function fullStackTrace() {
- this.options = (0, _extends3.default)({}, this.options, {
- fullStackTrace: true
- });
- return this;
- }
- /**
- * Emit color output.
- *
- * @public
- * @param {boolean} colors
- * @return {MochaWebpack}
- */
- }, {
- key: 'useColors',
- value: function useColors(colors) {
- this.options = (0, _extends3.default)({}, this.options, {
- colors: colors
- });
- return this;
- }
- /**
- * Quiet informational messages.
- *
- * @public
- * @return {MochaWebpack}
- */
- }, {
- key: 'quiet',
- value: function quiet() {
- this.options = (0, _extends3.default)({}, this.options, {
- quiet: true
- });
- return this;
- }
- /**
- * Use inline diffs rather than +/-.
- *
- * @public
- * @param {boolean} inlineDiffs
- * @return {MochaWebpack}
- */
- }, {
- key: 'useInlineDiffs',
- value: function useInlineDiffs(inlineDiffs) {
- this.options = (0, _extends3.default)({}, this.options, {
- useInlineDiffs: inlineDiffs
- });
- return this;
- }
- /**
- * Set the timeout in milliseconds. Value of 0 disables timeouts
- *
- * @public
- * @param {number} timeout time in ms
- * @return {MochaWebpack}
- */
- }, {
- key: 'timeout',
- value: function (_timeout) {
- function timeout(_x5) {
- return _timeout.apply(this, arguments);
- }
- timeout.toString = function () {
- return _timeout.toString();
- };
- return timeout;
- }(function (timeout) {
- this.options = (0, _extends3.default)({}, this.options, {
- timeout: timeout
- });
- return this;
- })
- /**
- * Set the number of times to retry failed tests.
- *
- * @public
- * @param {number} count retry times
- * @return {MochaWebpack}
- */
- }, {
- key: 'retries',
- value: function retries(count) {
- this.options = (0, _extends3.default)({}, this.options, {
- retries: count
- });
- return this;
- }
- /**
- * Set slowness threshold in milliseconds.
- *
- * @public
- * @param {number} threshold time in ms
- * @return {MochaWebpack}
- */
- }, {
- key: 'slow',
- value: function slow(threshold) {
- this.options = (0, _extends3.default)({}, this.options, {
- slow: threshold
- });
- return this;
- }
- /**
- * Makes all tests async (accepting a callback)
- *
- * @public
- * @return {MochaWebpack}
- */
- }, {
- key: 'asyncOnly',
- value: function asyncOnly() {
- this.options = (0, _extends3.default)({}, this.options, {
- asyncOnly: true
- });
- return this;
- }
- /**
- * Delay root suite execution.
- *
- * @public
- * @return {MochaWebpack}
- */
- }, {
- key: 'delay',
- value: function delay() {
- this.options = (0, _extends3.default)({}, this.options, {
- delay: true
- });
- return this;
- }
- /**
- * Force interactive mode (default enabled in terminal)
- *
- * @public
- * @param {boolean} interactive
- * @return {MochaWebpack}
- */
- }, {
- key: 'interactive',
- value: function (_interactive) {
- function interactive(_x6) {
- return _interactive.apply(this, arguments);
- }
- interactive.toString = function () {
- return _interactive.toString();
- };
- return interactive;
- }(function (interactive) {
- this.options = (0, _extends3.default)({}, this.options, {
- interactive: interactive
- });
- return this;
- })
- /**
- * Enable growl notification support
- *
- * @public
- * @param {boolean} growl
- * @return {MochaWebpack}
- */
- }, {
- key: 'growl',
- value: function growl() {
- this.options = (0, _extends3.default)({}, this.options, {
- growl: true
- });
- return this;
- }
- /**
- * Run tests
- *
- * @public
- * @return {Promise<number>} a Promise that gets resolved with the number of failed tests or rejected with build error
- */
- }, {
- key: 'run',
- value: function run() {
- return new Promise(function ($return, $error) {
- var runner = new _TestRunner2.default(this.entries, this.includes, this.options);
- (0, _testRunnerReporter2.default)({
- eventEmitter: runner,
- interactive: this.options.interactive,
- quiet: this.options.quiet,
- cwd: this.options.cwd
- });
- return $return(runner.run());
- }.$asyncbind(this));
- }
- /**
- * Run tests and rerun them on changes
- * @public
- */
- }, {
- key: 'watch',
- value: function watch() {
- return new Promise(function ($return, $error) {
- var runner;
- runner = new _TestRunner2.default(this.entries, this.includes, this.options);
- (0, _testRunnerReporter2.default)({
- eventEmitter: runner,
- interactive: this.options.interactive,
- quiet: this.options.quiet,
- cwd: this.options.cwd
- });
- return runner.watch().then(function ($await_1) {
- return $return();
- }.$asyncbind(this, $error), $error);
- }.$asyncbind(this));
- }
- }]);
- return MochaWebpack;
- }();
- exports.default = MochaWebpack;
|