UNPKG

gherkin-ast

Version:

JS model for Gherkin feature files

94 lines 7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScenarioOutline = void 0; const common_1 = require("../common"); const element_1 = require("./element"); const examples_1 = require("./examples"); const scenario_1 = require("./scenario"); const step_1 = require("./step"); const tag_1 = require("./tag"); const debug_1 = require("../debug"); const debug = (0, debug_1.getDebugger)("ScenarioOutline"); /** * Model for ScenarioOutline */ class ScenarioOutline extends element_1.Element { static parse(obj, comments) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; debug("parse(obj: %o, comments: %d)", obj, (_a = comments === null || comments === void 0 ? void 0 : comments.comments) === null || _a === void 0 ? void 0 : _a.length); if (!obj || !obj.scenario || !Array.isArray(obj.scenario.examples)) { throw new TypeError("The given object is not a Scenario Outline!"); } const { description, examples, keyword, name, steps, tags, location } = obj.scenario; const scenarioOutline = new ScenarioOutline(keyword, name, description); scenarioOutline.precedingComment = comments === null || comments === void 0 ? void 0 : comments.parseComment(location, (_b = tags === null || tags === void 0 ? void 0 : tags[tags.length - 1]) === null || _b === void 0 ? void 0 : _b.location); scenarioOutline.tagComment = comments === null || comments === void 0 ? void 0 : comments.parseTagComment(tags); scenarioOutline.steps = step_1.Step.parseAll(steps, comments); scenarioOutline.tags = tag_1.Tag.parseAll(tags, comments); scenarioOutline.descriptionComment = comments === null || comments === void 0 ? void 0 : comments.parseCommentBetween(location, (_c = steps === null || steps === void 0 ? void 0 : steps[0]) === null || _c === void 0 ? void 0 : _c.location); scenarioOutline.examples = examples.map(e => examples_1.Examples.parse(e, comments)); debug("parse(this: {keyword: '%s', name: '%s', description: '%s', " + "steps: %d, tags: %d, examples: %d, precedingComment: '%s', tagComment: '%s', " + "descriptionComment: '%s'})", scenarioOutline.keyword, scenarioOutline.name, scenarioOutline.description, (_d = scenarioOutline.steps) === null || _d === void 0 ? void 0 : _d.length, (_e = scenarioOutline.tags) === null || _e === void 0 ? void 0 : _e.length, (_f = scenarioOutline.examples) === null || _f === void 0 ? void 0 : _f.length, (_g = scenarioOutline.precedingComment) === null || _g === void 0 ? void 0 : _g.text, (_h = scenarioOutline.tagComment) === null || _h === void 0 ? void 0 : _h.text, (_j = scenarioOutline.descriptionComment) === null || _j === void 0 ? void 0 : _j.text); return scenarioOutline; } constructor(keyword, name, description) { var _a, _b, _c, _d, _e, _f; super(keyword, name, description); debug("constructor(keyword: '%s', name: '%s', description: '%s')", keyword, name, description); this.tags = []; this.examples = []; this.tagComment = null; debug("constructor(this: {keyword: '%s', name: '%s', description: '%s', " + "steps: %d, tags: %d, examples: %d, precedingComment: '%s', tagComment: '%s', " + "descriptionComment: '%s'})", this.keyword, this.name, this.description, (_a = this.steps) === null || _a === void 0 ? void 0 : _a.length, (_b = this.tags) === null || _b === void 0 ? void 0 : _b.length, (_c = this.examples) === null || _c === void 0 ? void 0 : _c.length, (_d = this.precedingComment) === null || _d === void 0 ? void 0 : _d.text, (_e = this.tagComment) === null || _e === void 0 ? void 0 : _e.text, (_f = this.descriptionComment) === null || _f === void 0 ? void 0 : _f.text); } replace(key, value) { debug("replace(key: '%s', value: '%s')", key, value); super.replace(key, value); (0, common_1.replaceArray)(this.tags, key, value); (0, common_1.replaceArray)(this.examples, key, value); this.tagComment && this.tagComment.replace(key, value); } clone() { var _a, _b, _c, _d, _e, _f; debug("clone(this: {keyword: '%s', name: '%s', description: '%s', " + "steps: %d, tags: %d, examples: %d, precedingComment: '%s', tagComment: '%s', " + "descriptionComment: '%s'})", this.keyword, this.name, this.description, (_a = this.steps) === null || _a === void 0 ? void 0 : _a.length, (_b = this.tags) === null || _b === void 0 ? void 0 : _b.length, (_c = this.examples) === null || _c === void 0 ? void 0 : _c.length, (_d = this.precedingComment) === null || _d === void 0 ? void 0 : _d.text, (_e = this.tagComment) === null || _e === void 0 ? void 0 : _e.text, (_f = this.descriptionComment) === null || _f === void 0 ? void 0 : _f.text); const scenarioOutline = new ScenarioOutline(this.keyword, this.name, this.description); scenarioOutline.precedingComment = this.precedingComment ? this.precedingComment.clone() : null; scenarioOutline.tagComment = this.tagComment ? this.tagComment.clone() : null; scenarioOutline.descriptionComment = this.descriptionComment ? this.descriptionComment.clone() : null; scenarioOutline.tags = (0, common_1.cloneArray)(this.tags); scenarioOutline.steps = (0, common_1.cloneArray)(this.steps); scenarioOutline.examples = (0, common_1.cloneArray)(this.examples); return scenarioOutline; } toScenario(columnToAddAsTag = 0) { debug("toScenario(columnToAddAsTag: %d)", columnToAddAsTag); const scenarios = []; this.examples.forEach((examples) => { const n = Math.max(0, Math.min(examples.header.cells.length - 1, columnToAddAsTag)); examples.body.forEach((row) => { const scenario = new scenario_1.Scenario("Scenario", this.name, this.description); scenario.tags = (0, tag_1.removeDuplicateTags)([ ...(0, common_1.cloneArray)(this.tags), ...(0, common_1.cloneArray)(examples.tags), (0, tag_1.tag)(examples.header.cells[n].value, row.cells[n].value), ]); scenario.precedingComment = this.precedingComment ? this.precedingComment.clone() : null; scenario.tagComment = this.tagComment ? this.tagComment.clone() : null; scenario.descriptionComment = this.descriptionComment ? this.descriptionComment.clone() : null; scenario.steps = (0, common_1.cloneArray)(this.steps); examples.header.cells.forEach((cell, i) => { scenario.replace(`<${cell.value}>`, row.cells[i].value); }); scenarios.push(scenario); }); }); debug("toScenario(scenarios: %d)", scenarios.length); return scenarios; } } exports.ScenarioOutline = ScenarioOutline; //# sourceMappingURL=scenarioOutline.js.map