UNPKG

jest-cucumber

Version:
31 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateScenarioCodeWithSeparateStepFunctions = exports.generateScenarioCode = void 0; var step_generation_1 = require("./step-generation"); var utils_1 = require("./utils"); var scenarioTemplate = function (scenarioTitle, steps, stepKeywords) { // tslint:disable-next-line:max-line-length return "test('" + scenarioTitle.replace(/'+/g, "\\'") + "', ({ " + stepKeywords.join(', ') + " }) => {\n" + utils_1.indent(steps, 1).slice(0, -1) + "\n});"; }; var getStepKeywords = function (scenario) { var stepKeywords = []; scenario.steps.forEach(function (step) { if (stepKeywords.indexOf(step.keyword) === -1) { stepKeywords.push(step.keyword); } }); return stepKeywords; }; exports.generateScenarioCode = function (scenario) { var stepsCode = scenario.steps.map(function (step, index) { return step_generation_1.generateStepCode(scenario.steps, index); }); var stepKeywords = getStepKeywords(scenario); return scenarioTemplate(scenario.title, stepsCode.join('\n\n'), stepKeywords); }; exports.generateScenarioCodeWithSeparateStepFunctions = function (scenario) { var stepFunctionCode = scenario.steps.map(function (step, index) { return step_generation_1.generateStepCode(scenario.steps, index, true); }); var stepFunctionCalls = scenario.steps.map(function (step, index) { return step_generation_1.generateStepFunctionCall(scenario.steps, index); }); var stepKeywords = getStepKeywords(scenario); // tslint:disable-next-line:max-line-length return stepFunctionCode.join('\n\n') + "\n\n" + scenarioTemplate(scenario.title, stepFunctionCalls.join('\n'), stepKeywords); }; //# sourceMappingURL=scenario-generation.js.map