UNPKG

@serenity-js/core

Version:

The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure

127 lines 4.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExecutionSuccessful = exports.ExecutionSkipped = exports.ExecutionIgnored = exports.ImplementationPending = exports.ExecutionFailedWithAssertionError = exports.ExecutionFailedWithError = exports.ExecutionCompromised = exports.ProblemIndication = exports.Outcome = void 0; const tiny_types_1 = require("tiny-types"); const errors_1 = require("../errors"); class Outcome extends tiny_types_1.TinyType { code; static fromJSON = (o) => (0, tiny_types_1.match)(o.code) .when(ExecutionCompromised.Code, _ => ExecutionCompromised.fromJSON(o)) .when(ExecutionFailedWithError.Code, _ => ExecutionFailedWithError.fromJSON(o)) .when(ExecutionFailedWithAssertionError.Code, _ => ExecutionFailedWithAssertionError.fromJSON(o)) .when(ImplementationPending.Code, _ => ImplementationPending.fromJSON(o)) .when(ExecutionIgnored.Code, _ => ExecutionIgnored.fromJSON(o)) .when(ExecutionSkipped.Code, _ => ExecutionSkipped.fromJSON(o)) .when(ExecutionSuccessful.Code, _ => ExecutionSuccessful.fromJSON(o)) .else(_ => { throw new Error(`Outcome could not be deserialised: ${JSON.stringify(o)}`); }); constructor(code) { super(); this.code = code; } isWorseThan(another) { const code = (another instanceof Outcome) ? another.code : another.Code; return this.code < code; } toJSON() { return { code: this.code, }; } } exports.Outcome = Outcome; class ProblemIndication extends Outcome { error; constructor(error, code) { super(code); this.error = error; } toJSON() { return { code: this.code, error: errors_1.ErrorSerialiser.serialise(this.error), }; } } exports.ProblemIndication = ProblemIndication; /** * Indicates a failure due to external events or systems that compromise the validity of the test. */ class ExecutionCompromised extends ProblemIndication { static Code = 1 << 0; static fromJSON = (o) => new ExecutionCompromised(errors_1.ErrorSerialiser.deserialise(o.error)); constructor(error) { super(error, ExecutionCompromised.Code); } } exports.ExecutionCompromised = ExecutionCompromised; /** * Indicates a failure due to an error other than recognised external system and assertion failures */ class ExecutionFailedWithError extends ProblemIndication { static Code = 1 << 1; static fromJSON = (o) => new ExecutionFailedWithError(errors_1.ErrorSerialiser.deserialise(o.error)); constructor(error) { super(error, ExecutionFailedWithError.Code); } } exports.ExecutionFailedWithError = ExecutionFailedWithError; /** * Execution of an Activity or Scene has failed due to an assertion error; */ class ExecutionFailedWithAssertionError extends ProblemIndication { static Code = 1 << 2; static fromJSON = (o) => new ExecutionFailedWithAssertionError(errors_1.ErrorSerialiser.deserialise(o.error)); constructor(error) { super(error, ExecutionFailedWithAssertionError.Code); } } exports.ExecutionFailedWithAssertionError = ExecutionFailedWithAssertionError; /** * A pending Activity is one that has been specified but not yet implemented. * A pending Scene is one that has at least one pending Activity. */ class ImplementationPending extends ProblemIndication { static Code = 1 << 3; static fromJSON = (o) => new ImplementationPending(errors_1.ErrorSerialiser.deserialise(o.error)); constructor(error) { super(error, ImplementationPending.Code); } } exports.ImplementationPending = ImplementationPending; /** * The result of the scenario should be ignored, most likely because it's going to be retried. */ class ExecutionIgnored extends ProblemIndication { static Code = 1 << 4; static fromJSON = (o) => new ExecutionIgnored(errors_1.ErrorSerialiser.deserialise(o.error)); constructor(error) { super(error, ExecutionIgnored.Code); } } exports.ExecutionIgnored = ExecutionIgnored; /** * The Activity was not executed because a previous one has failed. * A whole Scene can be marked as skipped to indicate that it is currently "work-in-progress" */ class ExecutionSkipped extends Outcome { static Code = 1 << 5; static fromJSON = (o) => new ExecutionSkipped(); constructor() { super(ExecutionSkipped.Code); } } exports.ExecutionSkipped = ExecutionSkipped; /** * Scenario or activity ran as expected. */ class ExecutionSuccessful extends Outcome { static Code = 1 << 6; static fromJSON = (o) => new ExecutionSuccessful(); constructor() { super(ExecutionSuccessful.Code); } } exports.ExecutionSuccessful = ExecutionSuccessful; //# sourceMappingURL=outcomes.js.map