UNPKG

@mhy/config

Version:

> This documentation is not complete. It's in progress and it's a BETA version. Use the tool at your own risk.

109 lines (87 loc) 2.92 kB
"use strict"; var _path = _interopRequireDefault(require("path")); var _dist = _interopRequireDefault(require("@mhy/process/dist")); var _ = require("../.."); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const onlyChangedFlag = '--onlyChanged'; const watchFlag = '--watch'; const watchAllFlag = '--watchAll'; const getJestCLICmd = (flags = []) => { return ['node', require.resolve('jest-cli/bin/jest.js'), '--passWithNoTests', `--config=${_path.default.resolve(_.moduleHome, 'jest/index.js')}`, ...flags]; }; const getJestServeCLICmd = flags => ['node', require.resolve('chokidar-cli/index.js'), `"src/**/*.js"`, `"src/**/*.jsx"`, `"src/**/*.ts"`, `"src/**/*.tsx"`, '-c', `"${getJestCLICmd(flags).join(' ')}"`, '--initial', '--ignore', '"node_modules"']; class Jest extends _dist.default { get commandToUse() { return process.MHY_ENV === 'ui' ? getJestServeCLICmd : getJestCLICmd; } constructor(args) { const { args: [defaultAction = 'start'], flags: _flags } = args; super(args); _defineProperty(this, "onStart", ({ name }, { flags = [] }) => this.spawn(name, this.commandToUse(flags))); _defineProperty(this, "onWatch", ({ name }, { flags = [] }) => this.spawn(name, this.commandToUse([...flags, watchFlag]))); _defineProperty(this, "onWatchAll", ({ name }, { flags = [] }) => this.spawn(name, this.commandToUse([...flags, watchAllFlag]))); _defineProperty(this, "onRunAll", async () => { await this.kill('start'); this.run('start'); }); _defineProperty(this, "onOnlyChanged", async () => { await this.kill('start'); this.run('start', { flags: [onlyChangedFlag] }); }); _defineProperty(this, "actions", [{ name: 'start', enabled: true, onRun: this.onStart }, { name: 'changed', label: 'Only Changed', shortcut: 'c', enabled: true, onRun: this.onOnlyChanged }, { name: 'all', label: 'Run All', shortcut: 'a', enabled: true, onRun: this.onRunAll }, { name: 'watch', enabled: true, onRun: this.onWatch }, { name: 'watch-all', enabled: true, onRun: this.onWatchAll }]); this.run(defaultAction, { flags: _flags }); } // Feature test only processLine(d) { if (d.startsWith('change:')) { this.emit('action', 'clear'); } return d.replace('PASS', '{green-bg} PASS {/green-bg}').replace('FAIL', '{red-bg} FAIL {/red-bg}'); } } _defineProperty(Jest, "isEnabled", true); module.exports.default = () => Jest;