UNPKG

@pact-foundation/pact

Version:
44 lines 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupStates = void 0; const logger_1 = __importDefault(require("../../../../common/logger")); const isStateFuncWithSetup = (fn) => fn.setup !== undefined || fn.teardown !== undefined; // Transform a regular state function to one with the setup/teardown functions const transformStateFunc = (fn) => isStateFuncWithSetup(fn) ? fn : { setup: fn }; // Lookup the handler based on the description const setupStates = (state, config) => { logger_1.default.debug(`setting up state '${JSON.stringify(state)}'`); const handler = config.stateHandlers ? config.stateHandlers[state.state] : null; if (!handler) { if (state.action === 'setup') { logger_1.default.warn(`no state handler found for state: "${state.state}"`); } return Promise.resolve(undefined); } const stateFn = transformStateFunc(handler); switch (state.action) { case 'setup': if (stateFn.setup) { logger_1.default.debug(`setting up state '${state.state}'`); return stateFn.setup(state.params); } break; case 'teardown': if (stateFn.teardown) { logger_1.default.debug(`tearing down state '${state.state}'`); return stateFn.teardown(state.params); } break; default: logger_1.default.debug(`unknown state action '${state.action}' received, ignoring`); } return Promise.resolve(undefined); }; exports.setupStates = setupStates; //# sourceMappingURL=setupStates.js.map