UNPKG

skutter

Version:

Skutter: Opinionated BDD Browser based test framework

58 lines (57 loc) 1.82 kB
"use strict"; const step_statuses_1 = require("./step-statuses"); class StepResult { constructor(step, index) { this._status = step_statuses_1.StepStatuses.Pending; this.log = []; this._step = step; this._index = index; this.log = []; this.screenshots = []; this.error = null; this.subSteps = []; } 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 step() { return this._step; } get durationMiliseconds() { return this.step.durationMiliseconds; } findSubStepResult(stepId) { 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.StepResult = StepResult;