UNPKG

jest-watch-suspend

Version:
47 lines 1.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; exports.__esModule = true; var chalk_1 = __importDefault(require("chalk")); var unpartial_1 = require("unpartial"); var WatchSuspendPlugin = /** @class */ (function () { function WatchSuspendPlugin(_a) { var config = _a.config; this.globalConfig = {}; this.log = console.info; this.config = unpartial_1.unpartial({ 'suspend-on-start': false, key: 's', prompt: 'suspend watch mode' }, config); this.suspend = this.config['suspend-on-start']; } // Add hooks to Jest lifecycle events WatchSuspendPlugin.prototype.apply = function (jestHooks) { var _this = this; jestHooks.shouldRunTestSuite(function () { return !_this.suspend; }); jestHooks.onTestRunComplete(function () { if (_this.suspend) { _this.log(chalk_1["default"].bold("Test is suspended.")); } }); }; // Get the prompt information for interactive plugins WatchSuspendPlugin.prototype.getUsageInfo = function () { return { key: this.config.key, prompt: this.suspend ? 'resume watch mode' : this.config.prompt }; }; // Executed when the key from `getUsageInfo` is input WatchSuspendPlugin.prototype.run = function (globalConfig) { this.globalConfig = globalConfig; this.suspend = !this.suspend; if (this.suspend) { this.log(chalk_1["default"].bold('\nTest is suspended.')); } return Promise.resolve(!this.suspend); }; return WatchSuspendPlugin; }()); exports.WatchSuspendPlugin = WatchSuspendPlugin; //# sourceMappingURL=WatchSuspendPlugin.js.map