Class FailingReporter

A reporter that fails as a test says, to check what a journey does when a reporter fails. It keeps what an EntryRecordingReporter keeps, the event or entry it fails on included, then throws an Error wherever one of its failures says, and remembers whether it ever did. Given no failure, it never fails.

import assert from "node:assert/strict";
import { LocalExecutor } from "itinera/executor";
import { AbortReason } from "itinera/journey";
import { Ending, FailingReporter, stepMock } from "itinera/testing";
import { Workflow } from "itinera/workflow";

class Orders extends Workflow {}

export default (async () => {
const orders = Orders.builder()
.name("orders")
.step(stepMock({ attempts: [Ending.success] }).builder("charge"))
.build();
const reporter = new FailingReporter({
kind: "on event",
event: "step_succeeded",
message: "audit log is full",
});

const result = await new LocalExecutor().run(
orders.instance({}, { reporters: [reporter] }),
);

assert.equal(result.abort?.reason, AbortReason.ReporterFailed);
assert.ok(reporter.failed);
assert.deepEqual(reporter.path, ["charge attempt 1 succeeded"]);
})();

Hierarchy (View Summary)

Index

  • get events(): readonly Event[]

    Every event it has received so far, in the order it received them.

    Returns readonly Event[]

  • get globalMetadata(): ReadonlyMap<string, PlainValue>

    The global metadata it has received so far: each key with its latest value, in the order the keys were first set. The journey ID is the first entry, under journey_id.

    Returns ReadonlyMap<string, PlainValue>

  • get path(): readonly string[]

    The path of the journey so far: one line for each event of its flow, in the order it received them, so that a test can compare it with the path it expects, or with an approved file through path.join("\n").

    Only the flow has lines: the outcome of each attempt, each decision on a step, and how the journey ended. Inputs, services, hooks, contributions, the events steps, hooks and service providers emit, and global metadata have none, and no line holds a timestamp, a sequence number or an ID, so a path changes only when the flow does. The lines read:

    • charge attempt 1 succeeded; charge attempt 1 failed: declined, with the reason's code; charge attempt 1 skipped, with : and the reason's code when it has one; and charge attempt 1 terminated abnormally: timeout, with the error's message. A rescue step's attempts read the same under its own name, such as charge_rescue.
    • charge retrying; charge given up: retries exhausted, or the other cause, failure or abnormal termination; and charge given up: FailWorkflow from fraud_check when a hook of the policy fraud_check gave it up.
    • charge rescuing with charge_rescue and charge rescued by charge_rescue.
    • journey succeeded, or journey succeeded, decided by early_exit when a hook of the policy early_exit decided it; journey failed at charge: declined, with the code of the reason the journey failed for, or the error's message when there is no reason; and journey aborted at charge: step could not be built, with the abort reason, or journey aborted: reporter failed when the abort concerns no step.

    A refused journey has no events, so its path is empty.

    Returns readonly string[]