Innovenergy_trunk/frontend/node_modules/testcafe/lib/live/controller.js

109 lines
13 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = __importDefault(require("events"));
const logger_1 = __importDefault(require("./logger"));
const file_watcher_1 = __importDefault(require("./file-watcher"));
const keyboard_observer_1 = __importDefault(require("./keyboard-observer"));
const types_1 = require("../errors/types");
const runtime_1 = require("../errors/runtime");
class LiveModeController extends events_1.default {
constructor(runner) {
super();
this.running = false;
this.restarting = false;
this.watchingPaused = false;
this.stopping = false;
this.logger = new logger_1.default();
this.runner = runner;
this.keyboardObserver = this._createKeyboardObserver();
this.fileWatcher = this._createFileWatcher();
}
_isTestFilesNotFoundError(err) {
// @ts-ignore
return runtime_1.GeneralError.isGeneralError(err) && err.code === types_1.RUNTIME_ERRORS.testFilesNotFound;
}
init(files) {
this.keyboardObserver.push(this);
this._initFileWatching(files);
this._setRunning();
return Promise.resolve()
.then(() => this.logger.writeIntroMessage(files));
}
dispose() {
this.fileWatcher.stop();
this.keyboardObserver.remove(this);
}
runTests(sourceChanged) {
if (this.watchingPaused || this.running)
return Promise.resolve();
this._setRunning();
this.logger.writeRunTestsMessage(sourceChanged);
return this.runner.runTests();
}
onTestRunDone(err) {
this.running = false;
if (this._isTestFilesNotFoundError(err))
throw err;
if (!this.restarting)
this.logger.writeTestsFinishedMessage();
if (err)
this.logger.err(err);
}
toggleWatching() {
this.watchingPaused = !this.watchingPaused;
this.logger.writeToggleWatchingMessage(!this.watchingPaused);
}
stop() {
if (!this.runner || !this.running) {
this.logger.writeNothingToStopMessage();
return Promise.resolve();
}
this.logger.writeStopRunningMessage();
return this.runner.suspend()
.then(() => {
this.restarting = false;
this.running = false;
});
}
restart() {
if (this.restarting || this.watchingPaused)
return Promise.resolve();
this.restarting = true;
if (this.running) {
return this.stop()
.then(() => this.logger.writeTestsFinishedMessage())
.then(() => this.runTests());
}
return this.runTests();
}
exit() {
if (this.stopping)
return Promise.resolve();
this.logger.writeExitMessage();
this.stopping = true;
return this.runner ? this.runner.exit() : Promise.resolve();
}
addFileToWatches(filename) {
this.fileWatcher.addFile(this, filename);
}
_createFileWatcher() {
return new file_watcher_1.default();
}
_createKeyboardObserver() {
return new keyboard_observer_1.default();
}
_initFileWatching(files) {
files.forEach(file => this.addFileToWatches(file));
}
_setRunning() {
this.running = true;
this.restarting = false;
this.stopping = false;
}
}
exports.default = LiveModeController;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJvbGxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9saXZlL2NvbnRyb2xsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxvREFBa0M7QUFDbEMsc0RBQThCO0FBQzlCLGtFQUF5QztBQUN6Qyw0RUFBZ0U7QUFFaEUsMkNBQWlEO0FBQ2pELCtDQUFpRDtBQUdqRCxNQUFNLGtCQUFtQixTQUFRLGdCQUFZO0lBZXpDLFlBQW9CLE1BQXNCO1FBQ3RDLEtBQUssRUFBRSxDQUFDO1FBRVIsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7UUFDckIsSUFBSSxDQUFDLFVBQVUsR0FBRyxLQUFLLENBQUM7UUFDeEIsSUFBSSxDQUFDLGNBQWMsR0FBRyxLQUFLLENBQUM7UUFDNUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxLQUFLLENBQUM7UUFDdEIsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLGdCQUFNLEVBQUUsQ0FBQztRQUMzQixJQUFJLENBQUMsTUFBTSxHQUFHLE1BQU0sQ0FBQztRQUVyQixJQUFJLENBQUMsZ0JBQWdCLEdBQUcsSUFBSSxDQUFDLHVCQUF1QixFQUFFLENBQUM7UUFDd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