UNPKG

declarative-e2e-test

Version:
46 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestBlock = void 0; const tested_request_1 = require("./tested-request"); const logger_1 = require("./utils/logger"); const logger = logger_1.Logger.getLogger(); class TestBlock { constructor(definition, globalRequestConfig = {}, app) { this.definition = definition; this.globalRequestConfig = globalRequestConfig; this.app = app; } generate() { const generateTestWithContext = (context) => this.generateTest(context), { name, skip, only } = this.definition; return { name, skip, only, test() { return generateTestWithContext(this); } }; } generateTest(context) { const testDefinitionArr = 'steps' in this.definition ? this.definition.steps : [this.definition]; const testRequestDetails = testDefinitionArr.length === 1 ? '1 request' : `${testDefinitionArr.length} steps`; logger.debug(`Starting test "${this.definition.name}" with ${testRequestDetails}, context:`, context); return testDefinitionArr .reduce((previousRequest, stepDef, stepIndex) => previousRequest.then(resp => { if (testDefinitionArr.length !== 1) { const requestIndexVsCount = `Request ${stepIndex + 1} out of ${testDefinitionArr.length}`, message = stepIndex === 0 ? [requestIndexVsCount] : [`${requestIndexVsCount}, previous request returned response`, resp]; logger.debug.apply(logger, message); } stepDef = typeof stepDef === 'function' ? stepDef(resp) : stepDef; return tested_request_1.TestedRequest.buildTestedRequest(stepDef, this.globalRequestConfig).run(context, this.app); }), Promise.resolve({})); } } exports.TestBlock = TestBlock; //# sourceMappingURL=test-block.js.map