skutter
Version:
Skutter: Opinionated BDD Browser based test framework
58 lines (57 loc) • 2.38 kB
JavaScript
;
const executor_states_1 = require("../executor/executor-states");
const executor_init_1 = require("../messages/executor-init");
const feature_dto_1 = require("../messages/feature-dto");
function logStdOut(data) {
this.log.push(data);
}
class ExecutorProxy {
constructor(childProcess, config, outputRootPath) {
if (!childProcess) {
throw new Error("[ExecutorProxy] childProcess is not specified.");
}
if (!config) {
throw new Error("[ExecutorProxy] config is not specified.");
}
if (!outputRootPath) {
throw new Error("[ExecutorProxy] outputRootPath is not specified.");
}
this.childProcess = childProcess;
this.executorConfig = config;
this._state = executor_states_1.ExecutorStates.Created;
this.log = [];
this.outputRootPath = outputRootPath;
this.childProcess.stdout.on("data", () => logStdOut.apply(this));
}
get state() {
return this._state;
}
start(features) {
let featureDtos = [];
for (let feature of features) {
featureDtos.push(new feature_dto_1.FeatureDTO(feature));
}
let initMessage = new executor_init_1.ExecutorInitMessage(this.outputRootPath, this.executorConfig.protractor, this.executorConfig.fullLibraryPaths, featureDtos, this.executorConfig.verbosity);
let executionPromise = new Promise((resolve, reject) => {
try {
this.childProcess.on("exit", () => {
this._state = executor_states_1.ExecutorStates.Finished;
resolve();
});
this.childProcess.send(initMessage, (error) => {
if (error) {
throw new Error(`Init message not successfully sent to child process ${this.childProcess.pid}. Additional error details: ${error}`);
}
});
this._state = executor_states_1.ExecutorStates.Executing;
}
catch (exception) {
console.error("Error during thread initialisation.", exception);
this._state = executor_states_1.ExecutorStates.Errored;
reject(exception.message);
}
});
return executionPromise;
}
}
exports.ExecutorProxy = ExecutorProxy;