Type Alias Mistake

Mistake:
    | {
        kind: | "unknown step"
        | "step scripted twice"
        | "rescue step skips"
        | "no contributor"
        | "no reporter"
        | "step left out";
        step: string;
    }
    | {
        attempt: number;
        kind: | "gap in the attempts"
        | "attempt scripted twice"
        | "no such attempt"
        | "attempt left out";
        step: string;
    }
    | { kind: "rescue step left out"; rescued: string; step: string }
    | { kind: "unknown provider" | "another service"; provider: string }

One mistake in a test: its kind, with the step, the attempt or the service provider it concerns, as the test named them.

import assert from "node:assert/strict";
import { type Outcome, Step, step } from "itinera/step";
import { MistakeKind, scripted, TestMistake } from "itinera/testing";
import { withStep, Workflow, workflow } from "itinera/workflow";

@step()
class Charge extends Step {
override run(): Outcome {
return this.succeed();
}
}

@workflow({ name: "orders" })
@withStep(Charge, { name: "charge", retryBudget: 1 })
class Orders extends Workflow {}

export default (async () => {
const instance = Orders.build().instance({});

assert.throws(
() => scripted(instance).step("chrage"),
new TestMistake([{ kind: MistakeKind.UnknownStep, step: "chrage" }]),
);

await assert.rejects(
scripted(instance).step("charge").willFail("declined").run(),
(mistake: unknown) =>
mistake instanceof TestMistake &&
mistake.message ===
"the test is mistaken: attempt 2 of charge is left out" &&
mistake.problems[0]?.kind === MistakeKind.AttemptLeftOut,
);
})();

Type Declaration

  • {
        kind:
            | "unknown step"
            | "step scripted twice"
            | "rescue step skips"
            | "no contributor"
            | "no reporter"
            | "step left out";
        step: string;
    }
    • Readonlykind:
          | "unknown step"
          | "step scripted twice"
          | "rescue step skips"
          | "no contributor"
          | "no reporter"
          | "step left out"

      Tells this mistake from the others.

    • Readonlystep: string

      The step, or rescue step, concerned.

  • {
        attempt: number;
        kind:
            | "gap in the attempts"
            | "attempt scripted twice"
            | "no such attempt"
            | "attempt left out";
        step: string;
    }
    • Readonlyattempt: number

      The attempt concerned: the one described out of order, or the first one left out, since those after it depend on how it ends.

    • Readonlykind:
          | "gap in the attempts"
          | "attempt scripted twice"
          | "no such attempt"
          | "attempt left out"

      Tells this mistake from the others.

    • Readonlystep: string

      The step, or rescue step, concerned.

  • { kind: "rescue step left out"; rescued: string; step: string }
    • Readonlykind: "rescue step left out"

      Tells this mistake from the others.

    • Readonlyrescued: string

      The step it rescues, which can fail on attempt 1.

    • Readonlystep: string

      The rescue step left out.

  • { kind: "unknown provider" | "another service"; provider: string }
    • Readonlykind: "unknown provider" | "another service"

      Tells this mistake from the others.

    • Readonlyprovider: string

      The service provider the fake is named after.