UNPKG

atool-test

Version:

Unit testing tool based on dora & mocha & webpack

86 lines (70 loc) 2.5 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _webpack = require('atool-build/lib/webpack'); var _webpack2 = _interopRequireDefault(_webpack); var _getTestWebpackCfg = require('./getTestWebpackCfg'); var _getTestWebpackCfg2 = _interopRequireDefault(_getTestWebpackCfg); var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar); var _path = require('path'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var webpackConfig = void 0; exports.default = { 'middleware.before': function middlewareBefore() { var _this = this; var _query = this.query, chai = _query.chai, coverage = _query.coverage, config = _query.config; webpackConfig = (0, _getTestWebpackCfg2.default)(chai, coverage, config); webpackConfig.plugins.push(new _webpack.ProgressPlugin(function (percentage, msg) { var stream = process.stderr; if (stream.isTTY && percentage < 0.71 && _this.get('__ready')) { stream.cursorTo(0); stream.write('\uD83D\uDCE6 ' + msg); stream.clearLine(1); } else if (percentage === 1) { console.log('\nwebpack: bundle build is now finished.'); } })); }, 'middleware': function middleware() { var compiler = (0, _webpack2.default)(webpackConfig); this.set('compiler', compiler); compiler.plugin('done', function (stats) { if (stats.hasErrors()) { console.log(stats.toString({ colors: true })); } }); return require('koa-webpack-dev-middleware')(compiler, { publicPath: '/tests', quiet: true }); }, 'server.after': function serverAfter() { var _this2 = this; var cwd = this.cwd, query = this.query; var webpackConfigPath = (0, _path.join)(cwd, query.config); _chokidar2.default.watch(webpackConfigPath).on('change', function () { _this2.restart(); }); _chokidar2.default.watch(['**/*-test.js', '**/*-spec.js'], { ignored: /node_modules/, ignoreInitial: true }).on('add', function (path) { console.log(); console.log('atool-test: File ' + path + ' has been added, restart...'); process.send('restart'); }).on('unlink', function (path) { console.log(); console.log('atool-test: File ' + path + ' has been removed, restart...'); process.send('restart'); }); } }; module.exports = exports['default'];