skutter
Version:
Skutter: Opinionated BDD Browser based test framework
64 lines (63 loc) • 2.07 kB
JavaScript
"use strict";
const Lazy = require("lazy.js");
const stop_watch_1 = require("../services/stop-watch");
const step_statuses_1 = require("./step-statuses");
class SubStepResult {
constructor(stepId, title, depth) {
this.stepId = stepId;
this.title = title;
this.depth = depth;
this._stopWatch = null;
this._status = step_statuses_1.StepStatuses.Pending;
this.log = [];
this.subSteps = [];
this._stopWatch = new stop_watch_1.StopWatch();
this._stopWatch.start();
}
stop() {
this._stopWatch.stop();
}
appendLog(lines) {
this.log.push(...lines);
}
appendScreenshot(filename) {
this.screenshots.push(filename);
}
setError(error) {
if (this._status !== step_statuses_1.StepStatuses.Pending) {
throw new Error("Cannot set the status of a step more than once.");
}
this._status = step_statuses_1.StepStatuses.Errored;
this.error = error;
}
setPassed() {
if (this._status !== step_statuses_1.StepStatuses.Pending) {
throw new Error("Cannot set the status of a step more than once.");
}
this._status = step_statuses_1.StepStatuses.Passed;
}
setFailed(reason) {
if (this._status !== step_statuses_1.StepStatuses.Pending) {
throw new Error("Cannot set the status of a step more than once.");
}
this._status = step_statuses_1.StepStatuses.Failed;
this.error = reason;
}
get result() {
return this._status;
}
get durationMiliseconds() {
return this._stopWatch.elapsedMilliseconds;
}
findSubStepResult(stepId) {
if (stepId === this.stepId) {
return this;
}
let results = Lazy(this.subSteps).map((subStep) => { return subStep.findSubStepResult(stepId); }).flatten().compact().toArray();
if (results || results.length === 1) {
return results[0];
}
return null;
}
}
exports.SubStepResult = SubStepResult;