@pact-foundation/pact
Version:
Pact for all things Javascript
30 lines (29 loc) • 1.39 kB
TypeScript
/**
* `beforeEach`/`afterEach` are driven off the provider-state setup/teardown
* requests the core makes to `/_pactSetup`. For each interaction the core sends
* one or more "setup" actions, runs the interaction, then sends one or more
* "teardown" actions.
*
* We track the interaction boundary with a single `insideInteraction` flag that
* flips on the setup<->teardown edges, rather than counting requests. This is:
* - idempotent under retries: the core retries a failed state-change request,
* and a duplicate "setup" while already inside an interaction is a no-op; and
* - self-healing: it cannot accumulate error and latch into a broken state.
*
* Hook failures are recorded on `HooksState.errors` and the state-change request
* is still answered with a success, so a throwing hook never turns into a non-2xx
* response (which the core would retry, desyncing interaction tracking). The
* verifier surfaces any recorded errors once verification completes, so a failing
* hook still fails the build.
*/
import type { RequestHandler } from 'express';
import type { Hook } from './types';
export type HooksState = {
insideInteraction: boolean;
errors: Error[];
};
export declare const createHooksState: () => HooksState;
export declare const registerHooks: (hooks: {
beforeEach?: Hook;
afterEach?: Hook;
}, hooksState: HooksState) => RequestHandler;