Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cucumber/gherkin-utils

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cucumber/gherkin-utils - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

dist/src/GherkinDocumentWalker.d.ts.map

4

.mocharc.json
{
"require": ["ts-node/register", "source-map-support/register"],
"require": ["tsconfig-paths/register", "ts-node/register", "source-map-support/register"],
"extension": ["ts", "tsx"],
"recursive": true,
"timeout": 10000
"timeout": 10000
}

@@ -39,1 +39,2 @@ import { messages } from '@cucumber/messages';

}
//# sourceMappingURL=GherkinDocumentWalker.d.ts.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rejectAllFilters = void 0;
var messages_1 = require("@cucumber/messages");
var defaultFilters = {
acceptScenario: function () { return true; },
acceptStep: function () { return true; },
acceptBackground: function () { return true; },
acceptRule: function () { return true; },
acceptFeature: function () { return true; },
const messages_1 = require("@cucumber/messages");
const defaultFilters = {
acceptScenario: () => true,
acceptStep: () => true,
acceptBackground: () => true,
acceptRule: () => true,
acceptFeature: () => true,
};
exports.rejectAllFilters = {
acceptScenario: function () { return false; },
acceptStep: function () { return false; },
acceptBackground: function () { return false; },
acceptRule: function () { return false; },
acceptFeature: function () { return false; },
acceptScenario: () => false,
acceptStep: () => false,
acceptBackground: () => false,
acceptRule: () => false,
acceptFeature: () => false,
};
var defaultHandlers = {
handleStep: function () { return null; },
handleScenario: function () { return null; },
handleBackground: function () { return null; },
handleRule: function () { return null; },
handleFeature: function () { return null; },
const defaultHandlers = {
handleStep: () => null,
handleScenario: () => null,
handleBackground: () => null,
handleRule: () => null,
handleFeature: () => null,
};
var GherkinDocumentWalker = /** @class */ (function () {
function GherkinDocumentWalker(filters, handlers) {
this.filters = __assign(__assign({}, defaultFilters), filters);
this.handlers = __assign(__assign({}, defaultHandlers), handlers);
class GherkinDocumentWalker {
constructor(filters, handlers) {
this.filters = Object.assign(Object.assign({}, defaultFilters), filters);
this.handlers = Object.assign(Object.assign({}, defaultHandlers), handlers);
}
GherkinDocumentWalker.prototype.walkGherkinDocument = function (gherkinDocument) {
walkGherkinDocument(gherkinDocument) {
if (!gherkinDocument.feature) {
return null;
}
var feature = this.walkFeature(gherkinDocument.feature);
const feature = this.walkFeature(gherkinDocument.feature);
if (!feature) {

@@ -66,13 +44,12 @@ return null;

});
};
GherkinDocumentWalker.prototype.walkFeature = function (feature) {
var _this = this;
var keptChildren = this.walkFeatureChildren(feature.children);
}
walkFeature(feature) {
const keptChildren = this.walkFeatureChildren(feature.children);
this.handlers.handleFeature(feature);
var backgroundKept = keptChildren.find(function (child) { return child.background; });
const backgroundKept = keptChildren.find((child) => child.background);
if (this.filters.acceptFeature(feature) || backgroundKept) {
return this.copyFeature(feature, feature.children.map(function (child) {
return this.copyFeature(feature, feature.children.map((child) => {
if (child.background) {
return messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
background: _this.copyBackground(child.background),
background: this.copyBackground(child.background),
});

@@ -82,3 +59,3 @@ }

return messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
scenario: _this.copyScenario(child.scenario),
scenario: this.copyScenario(child.scenario),
});

@@ -88,3 +65,3 @@ }

return messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
rule: _this.copyRule(child.rule, child.rule.children),
rule: this.copyRule(child.rule, child.rule.children),
});

@@ -94,7 +71,7 @@ }

}
if (keptChildren.find(function (child) { return child !== null; })) {
if (keptChildren.find((child) => child !== null)) {
return this.copyFeature(feature, keptChildren);
}
};
GherkinDocumentWalker.prototype.copyFeature = function (feature, children) {
}
copyFeature(feature, children) {
return messages_1.messages.GherkinDocument.Feature.create({

@@ -109,93 +86,65 @@ children: this.filterFeatureChildren(feature, children),

});
};
GherkinDocumentWalker.prototype.copyTags = function (tags) {
return tags.map(function (tag) {
return messages_1.messages.GherkinDocument.Feature.Tag.create({
name: tag.name,
id: tag.id,
location: tag.location,
});
});
};
GherkinDocumentWalker.prototype.filterFeatureChildren = function (feature, children) {
var e_1, _a;
var copyChildren = [];
var scenariosKeptById = new Map(children
.filter(function (child) { return child.scenario; })
.map(function (child) { return [child.scenario.id, child]; }));
var ruleKeptById = new Map(children
.filter(function (child) { return child.rule; })
.map(function (child) { return [child.rule.id, child]; }));
try {
for (var _b = __values(feature.children), _c = _b.next(); !_c.done; _c = _b.next()) {
var child = _c.value;
if (child.background) {
copyChildren.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
background: this.copyBackground(child.background),
}));
}
copyTags(tags) {
return tags.map((tag) => messages_1.messages.GherkinDocument.Feature.Tag.create({
name: tag.name,
id: tag.id,
location: tag.location,
}));
}
filterFeatureChildren(feature, children) {
const copyChildren = [];
const scenariosKeptById = new Map(children.filter((child) => child.scenario).map((child) => [child.scenario.id, child]));
const ruleKeptById = new Map(children.filter((child) => child.rule).map((child) => [child.rule.id, child]));
for (const child of feature.children) {
if (child.background) {
copyChildren.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
background: this.copyBackground(child.background),
}));
}
if (child.scenario) {
const scenarioCopy = scenariosKeptById.get(child.scenario.id);
if (scenarioCopy) {
copyChildren.push(scenarioCopy);
}
if (child.scenario) {
var scenarioCopy = scenariosKeptById.get(child.scenario.id);
if (scenarioCopy) {
copyChildren.push(scenarioCopy);
}
}
if (child.rule) {
const ruleCopy = ruleKeptById.get(child.rule.id);
if (ruleCopy) {
copyChildren.push(ruleCopy);
}
if (child.rule) {
var ruleCopy = ruleKeptById.get(child.rule.id);
if (ruleCopy) {
copyChildren.push(ruleCopy);
}
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return copyChildren;
};
GherkinDocumentWalker.prototype.walkFeatureChildren = function (children) {
var e_2, _a;
var childrenCopy = [];
try {
for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
var child = children_1_1.value;
var backgroundCopy = null;
var scenarioCopy = null;
var ruleCopy = null;
if (child.background) {
backgroundCopy = this.walkBackground(child.background);
}
if (child.scenario) {
scenarioCopy = this.walkScenario(child.scenario);
}
if (child.rule) {
ruleCopy = this.walkRule(child.rule);
}
if (backgroundCopy || scenarioCopy || ruleCopy) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
background: backgroundCopy,
scenario: scenarioCopy,
rule: ruleCopy,
}));
}
}
walkFeatureChildren(children) {
const childrenCopy = [];
for (const child of children) {
let backgroundCopy = null;
let scenarioCopy = null;
let ruleCopy = null;
if (child.background) {
backgroundCopy = this.walkBackground(child.background);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
if (child.scenario) {
scenarioCopy = this.walkScenario(child.scenario);
}
finally { if (e_2) throw e_2.error; }
if (child.rule) {
ruleCopy = this.walkRule(child.rule);
}
if (backgroundCopy || scenarioCopy || ruleCopy) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
background: backgroundCopy,
scenario: scenarioCopy,
rule: ruleCopy,
}));
}
}
return childrenCopy;
};
GherkinDocumentWalker.prototype.walkRule = function (rule) {
var children = this.walkRuleChildren(rule.children);
}
walkRule(rule) {
const children = this.walkRuleChildren(rule.children);
this.handlers.handleRule(rule);
var backgroundKept = children.find(function (child) { return child !== null && child.background !== null; });
var scenariosKept = children.filter(function (child) { return child !== null && child.scenario !== null; });
const backgroundKept = children.find((child) => child !== null && child.background !== null);
const scenariosKept = children.filter((child) => child !== null && child.scenario !== null);
if (this.filters.acceptRule(rule) || backgroundKept) {

@@ -207,4 +156,4 @@ return this.copyRule(rule, rule.children);

}
};
GherkinDocumentWalker.prototype.copyRule = function (rule, children) {
}
copyRule(rule, children) {
return messages_1.messages.GherkinDocument.Feature.FeatureChild.Rule.create({

@@ -218,70 +167,46 @@ id: rule.id,

});
};
GherkinDocumentWalker.prototype.filterRuleChildren = function (children, childrenKept) {
var e_3, _a;
var childrenCopy = [];
var scenariosKeptIds = childrenKept
.filter(function (child) { return child.scenario; })
.map(function (child) { return child.scenario.id; });
try {
for (var children_2 = __values(children), children_2_1 = children_2.next(); !children_2_1.done; children_2_1 = children_2.next()) {
var child = children_2_1.value;
if (child.background) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
background: this.copyBackground(child.background),
}));
}
if (child.scenario && scenariosKeptIds.includes(child.scenario.id)) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
scenario: this.copyScenario(child.scenario),
}));
}
}
filterRuleChildren(children, childrenKept) {
const childrenCopy = [];
const scenariosKeptIds = childrenKept
.filter((child) => child.scenario)
.map((child) => child.scenario.id);
for (const child of children) {
if (child.background) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
background: this.copyBackground(child.background),
}));
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (children_2_1 && !children_2_1.done && (_a = children_2.return)) _a.call(children_2);
if (child.scenario && scenariosKeptIds.includes(child.scenario.id)) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
scenario: this.copyScenario(child.scenario),
}));
}
finally { if (e_3) throw e_3.error; }
}
return childrenCopy;
};
GherkinDocumentWalker.prototype.walkRuleChildren = function (children) {
var e_4, _a;
var childrenCopy = [];
try {
for (var children_3 = __values(children), children_3_1 = children_3.next(); !children_3_1.done; children_3_1 = children_3.next()) {
var child = children_3_1.value;
if (child.background) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
background: this.walkBackground(child.background),
}));
}
if (child.scenario) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
scenario: this.walkScenario(child.scenario),
}));
}
}
walkRuleChildren(children) {
const childrenCopy = [];
for (const child of children) {
if (child.background) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
background: this.walkBackground(child.background),
}));
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (children_3_1 && !children_3_1.done && (_a = children_3.return)) _a.call(children_3);
if (child.scenario) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
scenario: this.walkScenario(child.scenario),
}));
}
finally { if (e_4) throw e_4.error; }
}
return childrenCopy;
};
GherkinDocumentWalker.prototype.walkBackground = function (background) {
var steps = this.walkAllSteps(background.steps);
}
walkBackground(background) {
const steps = this.walkAllSteps(background.steps);
this.handlers.handleBackground(background);
if (this.filters.acceptBackground(background) ||
steps.find(function (step) { return step !== null; })) {
if (this.filters.acceptBackground(background) || steps.find((step) => step !== null)) {
return this.copyBackground(background);
}
};
GherkinDocumentWalker.prototype.copyBackground = function (background) {
var _this = this;
}
copyBackground(background) {
return messages_1.messages.GherkinDocument.Feature.Background.create({

@@ -292,16 +217,14 @@ id: background.id,

keyword: background.keyword,
steps: background.steps.map(function (step) { return _this.copyStep(step); }),
steps: background.steps.map((step) => this.copyStep(step)),
description: background.description ? background.description : undefined,
});
};
GherkinDocumentWalker.prototype.walkScenario = function (scenario) {
var steps = this.walkAllSteps(scenario.steps);
}
walkScenario(scenario) {
const steps = this.walkAllSteps(scenario.steps);
this.handlers.handleScenario(scenario);
if (this.filters.acceptScenario(scenario) ||
steps.find(function (step) { return step !== null; })) {
if (this.filters.acceptScenario(scenario) || steps.find((step) => step !== null)) {
return this.copyScenario(scenario);
}
};
GherkinDocumentWalker.prototype.copyScenario = function (scenario) {
var _this = this;
}
copyScenario(scenario) {
return messages_1.messages.GherkinDocument.Feature.Scenario.create({

@@ -314,11 +237,10 @@ id: scenario.id,

examples: scenario.examples,
steps: scenario.steps.map(function (step) { return _this.copyStep(step); }),
steps: scenario.steps.map((step) => this.copyStep(step)),
tags: this.copyTags(scenario.tags),
});
};
GherkinDocumentWalker.prototype.walkAllSteps = function (steps) {
var _this = this;
return steps.map(function (step) { return _this.walkStep(step); });
};
GherkinDocumentWalker.prototype.walkStep = function (step) {
}
walkAllSteps(steps) {
return steps.map((step) => this.walkStep(step));
}
walkStep(step) {
this.handlers.handleStep(step);

@@ -329,4 +251,4 @@ if (!this.filters.acceptStep(step)) {

return this.copyStep(step);
};
GherkinDocumentWalker.prototype.copyStep = function (step) {
}
copyStep(step) {
return messages_1.messages.GherkinDocument.Feature.Step.create({

@@ -340,6 +262,5 @@ id: step.id,

});
};
return GherkinDocumentWalker;
}());
}
}
exports.default = GherkinDocumentWalker;
//# sourceMappingURL=GherkinDocumentWalker.js.map

@@ -5,1 +5,2 @@ import pretty from './pretty';

export { pretty, Query, GherkinDocumentWalker, rejectAllFilters };
//# sourceMappingURL=index.d.ts.map

@@ -26,9 +26,9 @@ "use strict";

exports.rejectAllFilters = exports.GherkinDocumentWalker = exports.Query = exports.pretty = void 0;
var pretty_1 = __importDefault(require("./pretty"));
const pretty_1 = __importDefault(require("./pretty"));
exports.pretty = pretty_1.default;
var Query_1 = __importDefault(require("./Query"));
const Query_1 = __importDefault(require("./Query"));
exports.Query = Query_1.default;
var GherkinDocumentWalker_1 = __importStar(require("./GherkinDocumentWalker"));
const GherkinDocumentWalker_1 = __importStar(require("./GherkinDocumentWalker"));
exports.GherkinDocumentWalker = GherkinDocumentWalker_1.default;
Object.defineProperty(exports, "rejectAllFilters", { enumerable: true, get: function () { return GherkinDocumentWalker_1.rejectAllFilters; } });
//# sourceMappingURL=index.js.map
import { messages } from '@cucumber/messages';
export default function pretty(gherkinDocument: messages.IGherkinDocument): string;
//# sourceMappingURL=pretty.d.ts.map
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
function pretty(gherkinDocument) {
var e_1, _a, e_2, _b;
var feature = gherkinDocument.feature;
var s = prettyTags(feature.tags);
const feature = gherkinDocument.feature;
let s = prettyTags(feature.tags);
s += feature.keyword + ': ' + feature.name + '\n';

@@ -22,44 +10,24 @@ if (feature.description) {

}
try {
for (var _c = __values(feature.children), _d = _c.next(); !_d.done; _d = _c.next()) {
var child = _d.value;
if (child.background) {
s += prettyStepContainer(child.background, ' ');
for (const child of feature.children) {
if (child.background) {
s += prettyStepContainer(child.background, ' ');
}
else if (child.scenario) {
s += prettyStepContainer(child.scenario, ' ');
}
else if (child.rule) {
s += `\n ${child.rule.keyword}: ${child.rule.name}\n`;
if (child.rule.description) {
s += child.rule.description + '\n';
}
else if (child.scenario) {
s += prettyStepContainer(child.scenario, ' ');
}
else if (child.rule) {
s += "\n " + child.rule.keyword + ": " + child.rule.name + "\n";
if (child.rule.description) {
s += child.rule.description + '\n';
for (const ruleChild of child.rule.children) {
if (ruleChild.background) {
s += prettyStepContainer(ruleChild.background, ' ');
}
try {
for (var _e = (e_2 = void 0, __values(child.rule.children)), _f = _e.next(); !_f.done; _f = _e.next()) {
var ruleChild = _f.value;
if (ruleChild.background) {
s += prettyStepContainer(ruleChild.background, ' ');
}
if (ruleChild.scenario) {
s += prettyStepContainer(ruleChild.scenario, ' ');
}
}
if (ruleChild.scenario) {
s += prettyStepContainer(ruleChild.scenario, ' ');
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
return s;

@@ -69,34 +37,13 @@ }

function prettyStepContainer(stepContainer, indent) {
var e_3, _a, e_4, _b;
var s = "\n" + prettyTags(stepContainer.tags, indent) + indent + stepContainer.keyword + ": " + stepContainer.name + "\n";
let s = `\n${prettyTags(stepContainer.tags, indent)}${indent}${stepContainer.keyword}: ${stepContainer.name}\n`;
if (stepContainer.description) {
s += stepContainer.description + '\n\n';
}
try {
for (var _c = __values(stepContainer.steps), _d = _c.next(); !_d.done; _d = _c.next()) {
var step = _d.value;
s += indent + " " + step.keyword + step.text + "\n";
}
for (const step of stepContainer.steps) {
s += `${indent} ${step.keyword}${step.text}\n`;
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_3) throw e_3.error; }
}
if (stepContainer.examples) {
try {
for (var _e = __values(stepContainer.examples), _f = _e.next(); !_f.done; _f = _e.next()) {
var example = _f.value;
s += prettyExample(example, indent + " ");
}
for (const example of stepContainer.examples) {
s += prettyExample(example, `${indent} `);
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_4) throw e_4.error; }
}
}

@@ -106,30 +53,18 @@ return s;

function prettyExample(example, indent) {
var e_5, _a;
var s = "\n" + indent + "Examples: " + example.name + "\n";
s += prettyTableRow(example.tableHeader, indent + " ");
try {
for (var _b = __values(example.tableBody), _c = _b.next(); !_c.done; _c = _b.next()) {
var row = _c.value;
s += prettyTableRow(row, indent + " ");
}
let s = `\n${indent}Examples: ${example.name}\n`;
s += prettyTableRow(example.tableHeader, `${indent} `);
for (const row of example.tableBody) {
s += prettyTableRow(row, `${indent} `);
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_5) throw e_5.error; }
}
return s;
}
function prettyTableRow(row, indent) {
return indent + "| " + row.cells.map(function (cell) { return cell.value; }).join(' | ') + " |\n";
return `${indent}| ${row.cells.map((cell) => cell.value).join(' | ')} |\n`;
}
function prettyTags(tags, indent) {
if (indent === void 0) { indent = ''; }
function prettyTags(tags, indent = '') {
if (tags === undefined || tags.length == 0) {
return '';
}
return indent + tags.map(function (tag) { return tag.name; }).join(' ') + '\n';
return indent + tags.map((tag) => tag.name).join(' ') + '\n';
}
//# sourceMappingURL=pretty.js.map

@@ -31,1 +31,2 @@ import { messages } from '@cucumber/messages';

}
//# sourceMappingURL=Query.d.ts.map
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
var multimaps_1 = require("@teppeis/multimaps");
var Query = /** @class */ (function () {
function Query() {
const multimaps_1 = require("@teppeis/multimaps");
class Query {
constructor() {
this.gherkinDocuments = [];

@@ -29,11 +18,11 @@ this.pickles = [];

*/
Query.prototype.getLocation = function (astNodeId) {
getLocation(astNodeId) {
return this.locationByAstNodeId.get(astNodeId);
};
Query.prototype.getGherkinDocuments = function () {
}
getGherkinDocuments() {
return this.gherkinDocuments;
};
Query.prototype.getPickles = function () {
}
getPickles() {
return this.pickles;
};
}
/**

@@ -44,13 +33,12 @@ * Gets all the pickle IDs

*/
Query.prototype.getPickleIds = function (uri, astNodeId) {
var pickleIdsByAstNodeId = this.pickleIdsMapByUri.get(uri);
getPickleIds(uri, astNodeId) {
const pickleIdsByAstNodeId = this.pickleIdsMapByUri.get(uri);
return astNodeId === undefined
? Array.from(new Set(pickleIdsByAstNodeId.values()))
: pickleIdsByAstNodeId.get(astNodeId);
};
Query.prototype.getPickleStepIds = function (astNodeId) {
}
getPickleStepIds(astNodeId) {
return this.pickleStepIdsByAstNodeId.get(astNodeId) || [];
};
Query.prototype.update = function (message) {
var e_1, _a, e_2, _b;
}
update(message) {
if (message.gherkinDocument) {

@@ -60,30 +48,17 @@ this.gherkinDocuments.push(message.gherkinDocument);

this.pickleIdsMapByUri.set(message.gherkinDocument.uri, new multimaps_1.ArrayMultimap());
try {
for (var _c = __values(message.gherkinDocument.feature.children), _d = _c.next(); !_d.done; _d = _c.next()) {
var featureChild = _d.value;
if (featureChild.background) {
this.updateGherkinBackground(featureChild.background);
}
if (featureChild.scenario) {
this.updateGherkinScenario(featureChild.scenario);
}
if (featureChild.rule) {
var ruleChildren = featureChild.rule.children;
try {
for (var ruleChildren_1 = (e_2 = void 0, __values(ruleChildren)), ruleChildren_1_1 = ruleChildren_1.next(); !ruleChildren_1_1.done; ruleChildren_1_1 = ruleChildren_1.next()) {
var ruleChild = ruleChildren_1_1.value;
if (ruleChild.background) {
this.updateGherkinBackground(ruleChild.background);
}
if (ruleChild.scenario) {
this.updateGherkinScenario(ruleChild.scenario);
}
}
for (const featureChild of message.gherkinDocument.feature.children) {
if (featureChild.background) {
this.updateGherkinBackground(featureChild.background);
}
if (featureChild.scenario) {
this.updateGherkinScenario(featureChild.scenario);
}
if (featureChild.rule) {
const ruleChildren = featureChild.rule.children;
for (const ruleChild of ruleChildren) {
if (ruleChild.background) {
this.updateGherkinBackground(ruleChild.background);
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (ruleChildren_1_1 && !ruleChildren_1_1.done && (_b = ruleChildren_1.return)) _b.call(ruleChildren_1);
}
finally { if (e_2) throw e_2.error; }
if (ruleChild.scenario) {
this.updateGherkinScenario(ruleChild.scenario);
}

@@ -93,149 +68,57 @@ }

}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
}
}
if (message.pickle) {
var pickle = message.pickle;
const pickle = message.pickle;
this.updatePickle(pickle);
}
return this;
};
Query.prototype.updateGherkinBackground = function (background) {
var e_3, _a;
try {
for (var _b = __values(background.steps), _c = _b.next(); !_c.done; _c = _b.next()) {
var step = _c.value;
this.updateGherkinStep(step);
}
}
updateGherkinBackground(background) {
for (const step of background.steps) {
this.updateGherkinStep(step);
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
};
Query.prototype.updateGherkinScenario = function (scenario) {
var e_4, _a, e_5, _b, e_6, _c;
}
updateGherkinScenario(scenario) {
this.locationByAstNodeId.set(scenario.id, scenario.location);
try {
for (var _d = __values(scenario.steps), _e = _d.next(); !_e.done; _e = _d.next()) {
var step = _e.value;
this.updateGherkinStep(step);
}
for (const step of scenario.steps) {
this.updateGherkinStep(step);
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
for (const examples of scenario.examples) {
for (const tableRow of examples.tableBody) {
this.locationByAstNodeId.set(tableRow.id, tableRow.location);
}
finally { if (e_4) throw e_4.error; }
}
try {
for (var _f = __values(scenario.examples), _g = _f.next(); !_g.done; _g = _f.next()) {
var examples = _g.value;
try {
for (var _h = (e_6 = void 0, __values(examples.tableBody)), _j = _h.next(); !_j.done; _j = _h.next()) {
var tableRow = _j.value;
this.locationByAstNodeId.set(tableRow.id, tableRow.location);
}
}
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {
try {
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
}
finally { if (e_6) throw e_6.error; }
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
}
finally { if (e_5) throw e_5.error; }
}
};
Query.prototype.updateGherkinStep = function (step) {
}
updateGherkinStep(step) {
this.locationByAstNodeId.set(step.id, step.location);
this.gherkinStepById.set(step.id, step);
};
Query.prototype.updatePickle = function (pickle) {
var e_7, _a, e_8, _b;
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(pickle.uri);
try {
for (var _c = __values(pickle.astNodeIds), _d = _c.next(); !_d.done; _d = _c.next()) {
var astNodeId = _d.value;
pickleIdsByLineNumber.put(astNodeId, pickle.id);
}
}
updatePickle(pickle) {
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(pickle.uri);
for (const astNodeId of pickle.astNodeIds) {
pickleIdsByLineNumber.put(astNodeId, pickle.id);
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_7) throw e_7.error; }
}
this.updatePickleSteps(pickle);
this.pickles.push(pickle);
try {
for (var _e = __values(pickle.astNodeIds), _f = _e.next(); !_f.done; _f = _e.next()) {
var astNodeId = _f.value;
if (!this.pickleIdsByAstNodeId.has(astNodeId)) {
this.pickleIdsByAstNodeId.set(astNodeId, []);
}
this.pickleIdsByAstNodeId.get(astNodeId).push(pickle.id);
for (const astNodeId of pickle.astNodeIds) {
if (!this.pickleIdsByAstNodeId.has(astNodeId)) {
this.pickleIdsByAstNodeId.set(astNodeId, []);
}
this.pickleIdsByAstNodeId.get(astNodeId).push(pickle.id);
}
catch (e_8_1) { e_8 = { error: e_8_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_8) throw e_8.error; }
}
};
Query.prototype.updatePickleSteps = function (pickle) {
var e_9, _a, e_10, _b;
var pickleSteps = pickle.steps;
try {
for (var pickleSteps_1 = __values(pickleSteps), pickleSteps_1_1 = pickleSteps_1.next(); !pickleSteps_1_1.done; pickleSteps_1_1 = pickleSteps_1.next()) {
var pickleStep = pickleSteps_1_1.value;
try {
for (var _c = (e_10 = void 0, __values(pickleStep.astNodeIds)), _d = _c.next(); !_d.done; _d = _c.next()) {
var astNodeId = _d.value;
if (!this.pickleStepIdsByAstNodeId.has(astNodeId)) {
this.pickleStepIdsByAstNodeId.set(astNodeId, []);
}
this.pickleStepIdsByAstNodeId.get(astNodeId).push(pickleStep.id);
}
}
updatePickleSteps(pickle) {
const pickleSteps = pickle.steps;
for (const pickleStep of pickleSteps) {
for (const astNodeId of pickleStep.astNodeIds) {
if (!this.pickleStepIdsByAstNodeId.has(astNodeId)) {
this.pickleStepIdsByAstNodeId.set(astNodeId, []);
}
catch (e_10_1) { e_10 = { error: e_10_1 }; }
finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
}
finally { if (e_10) throw e_10.error; }
}
this.pickleStepIdsByAstNodeId.get(astNodeId).push(pickleStep.id);
}
}
catch (e_9_1) { e_9 = { error: e_9_1 }; }
finally {
try {
if (pickleSteps_1_1 && !pickleSteps_1_1.done && (_a = pickleSteps_1.return)) _a.call(pickleSteps_1);
}
finally { if (e_9) throw e_9.error; }
}
};
return Query;
}());
}
}
exports.default = Query;
//# sourceMappingURL=Query.js.map
export {};
//# sourceMappingURL=GherkinDocumentWalkerTest.d.ts.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -36,9 +25,9 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
var assert_1 = __importDefault(require("assert"));
var GherkinDocumentWalker_1 = __importStar(require("../src/GherkinDocumentWalker"));
var pretty_1 = __importDefault(require("../src/pretty"));
var parse_1 = __importDefault(require("./parse"));
describe('GherkinDocumentWalker', function () {
var walker;
beforeEach(function () {
const assert_1 = __importDefault(require("assert"));
const GherkinDocumentWalker_1 = __importStar(require("../src/GherkinDocumentWalker"));
const pretty_1 = __importDefault(require("../src/pretty"));
const parse_1 = __importDefault(require("./parse"));
describe('GherkinDocumentWalker', () => {
let walker;
beforeEach(() => {
walker = new GherkinDocumentWalker_1.default();

@@ -50,5 +39,22 @@ });

}
it('returns a deep copy', function () {
var gherkinDocument = parse_1.default("@featureTag\nFeature: hello\n This feature has a description\n\n Background: Base Background\n This is a described background\n Given a passed step\n\n @scenarioTag\n Scenario: salut\n Yes, there is a description here too\n\n Rule: roule\n Can we describe a Rule ?\n\n Background: poupidou\n Scenario: pouet\n");
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
it('returns a deep copy', () => {
const gherkinDocument = parse_1.default(`@featureTag
Feature: hello
This feature has a description
Background: Base Background
This is a described background
Given a passed step
@scenarioTag
Scenario: salut
Yes, there is a description here too
Rule: roule
Can we describe a Rule ?
Background: poupidou
Scenario: pouet
`);
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
assertCopy(newGherkinDocument, gherkinDocument);

@@ -62,97 +68,269 @@ assertCopy(newGherkinDocument.feature, gherkinDocument.feature);

});
context('filtering objects', function () {
it('filters one scenario', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: function (scenario) { return scenario.name === 'Earth'; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Scenario: Earth\n Given is a planet with liquid water\n";
context('filtering objects', () => {
it('filters one scenario', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: (scenario) => scenario.name === 'Earth' }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Scenario: Earth
Given is a planet with liquid water
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('keeps scenario with search hit in step', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptStep: function (step) { return step.text.includes('liquid'); } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Scenario: Earth\n Given is a planet with liquid water\n";
it('keeps scenario with search hit in step', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptStep: (step) => step.text.includes('liquid') }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Scenario: Earth
Given is a planet with liquid water
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('does not leave null object as a feature child', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: function (scenario) { return scenario.name === 'Earth'; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
assert_1.default.deepStrictEqual(newGherkinDocument.feature.children.filter(function (child) { return child === null; }), []);
it('does not leave null object as a feature child', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: (scenario) => scenario.name === 'Earth' }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
assert_1.default.deepStrictEqual(newGherkinDocument.feature.children.filter((child) => child === null), []);
});
it('keeps a hit scenario even when no steps match', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: function (scenario) { return scenario.name === 'Saturn'; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n";
it('keeps a hit scenario even when no steps match', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: (scenario) => scenario.name === 'Saturn' }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('keeps a hit background', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Background: Space\n Given space is real\n\n Rule: Galaxy\n Background: Milky Way\n Given it contains our system\n\n Rule: Black Hole\n Background: TON 618\n Given it exists\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), {
acceptBackground: function (background) { return background.name === 'Milky Way'; },
it('keeps a hit background', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Background: Space
Given space is real
Rule: Galaxy
Background: Milky Way
Given it contains our system
Rule: Black Hole
Background: TON 618
Given it exists
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), {
acceptBackground: (background) => background.name === 'Milky Way',
}));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Background: Space\n Given space is real\n\n Rule: Galaxy\n\n Background: Milky Way\n Given it contains our system\n";
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Background: Space
Given space is real
Rule: Galaxy
Background: Milky Way
Given it contains our system
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('keeps a hit in background step', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Background: Space\n Given space is real\n\n Rule: Galaxy\n Background: Milky Way\n Given it contains our system\n\n Rule: Black Hole\n Background: TON 618\n Given it exists\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptStep: function (step) { return step.text.includes('space'); } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Background: Space\n Given space is real\n\n Rule: Galaxy\n\n Background: Milky Way\n Given it contains our system\n\n Rule: Black Hole\n\n Background: TON 618\n Given it exists\n";
it('keeps a hit in background step', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Background: Space
Given space is real
Rule: Galaxy
Background: Milky Way
Given it contains our system
Rule: Black Hole
Background: TON 618
Given it exists
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptStep: (step) => step.text.includes('space') }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Background: Space
Given space is real
Rule: Galaxy
Background: Milky Way
Given it contains our system
Rule: Black Hole
Background: TON 618
Given it exists
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('keeps scenario in rule', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Rule: Galaxy\n\n Background: TON 618\n Given it's a black hole\n\n Scenario: Milky Way\n Given it contains our system\n\n Scenario: Andromeda\n Given it exists\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: function (scenario) { return scenario.name === 'Andromeda'; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Rule: Galaxy\n\n Background: TON 618\n Given it's a black hole\n\n Scenario: Andromeda\n Given it exists\n";
it('keeps scenario in rule', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Rule: Galaxy
Background: TON 618
Given it's a black hole
Scenario: Milky Way
Given it contains our system
Scenario: Andromeda
Given it exists
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptScenario: (scenario) => scenario.name === 'Andromeda' }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Rule: Galaxy
Background: TON 618
Given it's a black hole
Scenario: Andromeda
Given it exists
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('keeps scenario and background in rule', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Rule: Galaxy\n\n Background: TON 618\n Given it's a black hole\n\n Scenario: Milky Way\n Given it contains our system\n\n Scenario: Andromeda\n Given it exists\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptRule: function (rule) { return rule.name === 'Galaxy'; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Rule: Galaxy\n\n Background: TON 618\n Given it's a black hole\n\n Scenario: Milky Way\n Given it contains our system\n\n Scenario: Andromeda\n Given it exists\n";
it('keeps scenario and background in rule', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Rule: Galaxy
Background: TON 618
Given it's a black hole
Scenario: Milky Way
Given it contains our system
Scenario: Andromeda
Given it exists
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptRule: (rule) => rule.name === 'Galaxy' }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Rule: Galaxy
Background: TON 618
Given it's a black hole
Scenario: Milky Way
Given it contains our system
Scenario: Andromeda
Given it exists
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('only keeps rule and its content', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Milky Way\n Given it contains our system\n\n Rule: Galaxy\n\n Scenario: Andromeda\n Given it exists\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptRule: function () { return true; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Rule: Galaxy\n\n Scenario: Andromeda\n Given it exists\n";
it('only keeps rule and its content', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Milky Way
Given it contains our system
Rule: Galaxy
Scenario: Andromeda
Given it exists
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptRule: () => true }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Rule: Galaxy
Scenario: Andromeda
Given it exists
`;
assert_1.default.strictEqual(newSource, expectedNewSource);
});
it('return a feature and keep scenario', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n");
var walker = new GherkinDocumentWalker_1.default(__assign(__assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptFeature: function (feature) { return feature.name === 'Solar System'; } }));
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
var newSource = pretty_1.default(newGherkinDocument);
var expectedNewSource = "Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n";
it('return a feature and keep scenario', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`);
const walker = new GherkinDocumentWalker_1.default(Object.assign(Object.assign({}, GherkinDocumentWalker_1.rejectAllFilters), { acceptFeature: (feature) => feature.name === 'Solar System' }));
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
const newSource = pretty_1.default(newGherkinDocument);
const expectedNewSource = `Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`;
assert_1.default.deepStrictEqual(newSource, expectedNewSource);
});
it('returns null when no hit found', function () {
var gherkinDocument = parse_1.default("Feature: Solar System\n\n Scenario: Saturn\n Given is the sixth planet from the Sun\n\n Scenario: Earth\n Given is a planet with liquid water\n");
var walker = new GherkinDocumentWalker_1.default(GherkinDocumentWalker_1.rejectAllFilters);
var newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
it('returns null when no hit found', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System
Scenario: Saturn
Given is the sixth planet from the Sun
Scenario: Earth
Given is a planet with liquid water
`);
const walker = new GherkinDocumentWalker_1.default(GherkinDocumentWalker_1.rejectAllFilters);
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument);
assert_1.default.deepEqual(newGherkinDocument, null);
});
});
context('handling objects', function () {
describe('handleStep', function () {
it('is called for each steps', function () {
var source = parse_1.default("Feature: Solar System\n\n Scenario: Earth\n Given it is a planet\n");
var stepText = [];
var astWalker = new GherkinDocumentWalker_1.default({}, {
handleStep: function (step) { return stepText.push(step.text); },
context('handling objects', () => {
describe('handleStep', () => {
it('is called for each steps', () => {
const source = parse_1.default(`Feature: Solar System
Scenario: Earth
Given it is a planet
`);
const stepText = [];
const astWalker = new GherkinDocumentWalker_1.default({}, {
handleStep: (step) => stepText.push(step.text),
});

@@ -163,8 +341,15 @@ astWalker.walkGherkinDocument(source);

});
describe('handleScenario', function () {
it('is called for each scenarios', function () {
var source = parse_1.default("Feature: Solar System\n\n Scenario: Earth\n Given it is a planet\n\n Scenario: Saturn\n Given it's not a liquid planet\n");
var scenarioName = [];
var astWalker = new GherkinDocumentWalker_1.default({}, {
handleScenario: function (scenario) { return scenarioName.push(scenario.name); },
describe('handleScenario', () => {
it('is called for each scenarios', () => {
const source = parse_1.default(`Feature: Solar System
Scenario: Earth
Given it is a planet
Scenario: Saturn
Given it's not a liquid planet
`);
const scenarioName = [];
const astWalker = new GherkinDocumentWalker_1.default({}, {
handleScenario: (scenario) => scenarioName.push(scenario.name),
});

@@ -175,10 +360,13 @@ astWalker.walkGherkinDocument(source);

});
describe('handleBackground', function () {
it('is called for each backgrounds', function () {
var source = parse_1.default("Feature: Solar System\n\n Background: Milky Way\n Scenario: Earth\n Given it is our galaxy\n");
var backgroundName = [];
var astWalker = new GherkinDocumentWalker_1.default({}, {
handleBackground: function (background) {
return backgroundName.push(background.name);
},
describe('handleBackground', () => {
it('is called for each backgrounds', () => {
const source = parse_1.default(`Feature: Solar System
Background: Milky Way
Scenario: Earth
Given it is our galaxy
`);
const backgroundName = [];
const astWalker = new GherkinDocumentWalker_1.default({}, {
handleBackground: (background) => backgroundName.push(background.name),
});

@@ -189,8 +377,17 @@ astWalker.walkGherkinDocument(source);

});
describe('handleRule', function () {
it('is called for each rules', function () {
var source = parse_1.default("Feature: Solar System\n\n Rule: On a planet\n Scenario: There is life\n Given there is water\n\n Rule: On an exoplanet\n Scenario: There is extraterrestrial life\n Given there is a non-humanoid form of life\n");
var ruleName = [];
var astWalker = new GherkinDocumentWalker_1.default({}, {
handleRule: function (rule) { return ruleName.push(rule.name); },
describe('handleRule', () => {
it('is called for each rules', () => {
const source = parse_1.default(`Feature: Solar System
Rule: On a planet
Scenario: There is life
Given there is water
Rule: On an exoplanet
Scenario: There is extraterrestrial life
Given there is a non-humanoid form of life
`);
const ruleName = [];
const astWalker = new GherkinDocumentWalker_1.default({}, {
handleRule: (rule) => ruleName.push(rule.name),
});

@@ -201,8 +398,17 @@ astWalker.walkGherkinDocument(source);

});
describe('handleFeature', function () {
it('is called for each features', function () {
var source = parse_1.default("Feature: Solar System\n\n Rule: On a planet\n Scenario: There is life\n Given there is water\n\n Rule: On an exoplanet\n Scenario: There is extraterrestrial life\n Given there is a non-humanoid form of life\n");
var featureName = [];
var astWalker = new GherkinDocumentWalker_1.default({}, {
handleFeature: function (feature) { return featureName.push(feature.name); },
describe('handleFeature', () => {
it('is called for each features', () => {
const source = parse_1.default(`Feature: Solar System
Rule: On a planet
Scenario: There is life
Given there is water
Rule: On an exoplanet
Scenario: There is extraterrestrial life
Given there is a non-humanoid form of life
`);
const featureName = [];
const astWalker = new GherkinDocumentWalker_1.default({}, {
handleFeature: (feature) => featureName.push(feature.name),
});

@@ -214,6 +420,6 @@ astWalker.walkGherkinDocument(source);

});
describe('regression tests', function () {
it('does not fail with empty/commented documents', function () {
var source = parse_1.default('# Feature: Solar System');
var astWalker = new GherkinDocumentWalker_1.default();
describe('regression tests', () => {
it('does not fail with empty/commented documents', () => {
const source = parse_1.default('# Feature: Solar System');
const astWalker = new GherkinDocumentWalker_1.default();
astWalker.walkGherkinDocument(source);

@@ -220,0 +426,0 @@ });

export {};
//# sourceMappingURL=messageTest.d.ts.map

@@ -11,40 +11,2 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -54,59 +16,36 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var messages_1 = require("@cucumber/messages");
var stream_1 = require("@cucumber/messages/dist/src/stream");
var stream_2 = require("stream");
var src_1 = require("../src");
var fs_1 = __importDefault(require("fs"));
var glob_1 = __importDefault(require("glob"));
var util_1 = require("util");
var asyncPipeline = util_1.promisify(stream_2.pipeline);
describe('Walking with messages', function () {
var e_1, _a;
var localMessageFiles = glob_1.default.sync(__dirname + "/messages/**/*.ndjson");
var tckMessageFiles = glob_1.default.sync(__dirname + "/../../../compatibility-kit/javascript/features/**/*.ndjson");
var messageFiles = [].concat(localMessageFiles, tckMessageFiles);
var _loop_1 = function (messageFile) {
it("can walk through GherkinDocuments in " + messageFile, function () { return __awaiter(void 0, void 0, void 0, function () {
var messageStream;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
messageStream = new stream_1.NdjsonToMessageStream(messages_1.messages.Envelope.fromObject.bind(messages_1.messages.Envelope));
return [4 /*yield*/, asyncPipeline(fs_1.default.createReadStream(messageFile, 'utf-8'), messageStream, new stream_2.Writable({
objectMode: true,
write: function (envelope, _encoding, callback) {
try {
if (envelope.gherkinDocument) {
var walker = new src_1.GherkinDocumentWalker();
walker.walkGherkinDocument(envelope.gherkinDocument);
}
callback();
}
catch (error) {
error.message += "\n" + envelope.gherkinDocument.uri + "\n";
callback(error);
}
},
}))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); }).timeout(30000);
};
try {
for (var messageFiles_1 = __values(messageFiles), messageFiles_1_1 = messageFiles_1.next(); !messageFiles_1_1.done; messageFiles_1_1 = messageFiles_1.next()) {
var messageFile = messageFiles_1_1.value;
_loop_1(messageFile);
}
const messages_1 = require("@cucumber/messages");
const message_streams_1 = require("@cucumber/message-streams");
const stream_1 = require("stream");
const src_1 = require("../src");
const fs_1 = __importDefault(require("fs"));
const glob_1 = __importDefault(require("glob"));
const util_1 = require("util");
const asyncPipeline = util_1.promisify(stream_1.pipeline);
describe('Walking with messages', () => {
const localMessageFiles = glob_1.default.sync(`${__dirname}/messages/**/*.ndjson`);
const tckMessageFiles = glob_1.default.sync(`${__dirname}/../../../compatibility-kit/javascript/features/**/*.ndjson`);
const messageFiles = [].concat(localMessageFiles, tckMessageFiles);
for (const messageFile of messageFiles) {
it(`can walk through GherkinDocuments in ${messageFile}`, () => __awaiter(void 0, void 0, void 0, function* () {
const messageStream = new message_streams_1.NdjsonToMessageStream(messages_1.messages.Envelope.fromObject.bind(messages_1.messages.Envelope));
yield asyncPipeline(fs_1.default.createReadStream(messageFile, 'utf-8'), messageStream, new stream_1.Writable({
objectMode: true,
write(envelope, _encoding, callback) {
try {
if (envelope.gherkinDocument) {
const walker = new src_1.GherkinDocumentWalker();
walker.walkGherkinDocument(envelope.gherkinDocument);
}
callback();
}
catch (error) {
error.message += `\n${envelope.gherkinDocument.uri}\n`;
callback(error);
}
},
}));
})).timeout(30000);
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (messageFiles_1_1 && !messageFiles_1_1.done && (_a = messageFiles_1.return)) _a.call(messageFiles_1);
}
finally { if (e_1) throw e_1.error; }
}
});
//# sourceMappingURL=messageTest.js.map
import { messages } from '@cucumber/messages';
export default function parse(source: string): messages.IGherkinDocument;
//# sourceMappingURL=parse.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var messages_1 = require("@cucumber/messages");
var gherkin_1 = require("@cucumber/gherkin");
const messages_1 = require("@cucumber/messages");
const gherkin_1 = require("@cucumber/gherkin");
function parse(source) {
var newId = messages_1.IdGenerator.uuid();
var parser = new gherkin_1.Parser(new gherkin_1.AstBuilder(newId));
var gherkinDocument = parser.parse(source);
const newId = messages_1.IdGenerator.uuid();
const parser = new gherkin_1.Parser(new gherkin_1.AstBuilder(newId), new gherkin_1.TokenMatcher());
const gherkinDocument = parser.parse(source);
gherkinDocument.uri = '';

@@ -10,0 +10,0 @@ return gherkinDocument;

export {};
//# sourceMappingURL=prettyTest.d.ts.map

@@ -6,32 +6,90 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var assert_1 = __importDefault(require("assert"));
var parse_1 = __importDefault(require("./parse"));
var pretty_1 = __importDefault(require("../src/pretty"));
describe('PrettyFormatter', function () {
it('renders a feature with no scenarios', function () {
const assert_1 = __importDefault(require("assert"));
const parse_1 = __importDefault(require("./parse"));
const pretty_1 = __importDefault(require("../src/pretty"));
describe('PrettyFormatter', () => {
it('renders a feature with no scenarios', () => {
assertPrettyIdentical('Feature: hello\n');
});
it('renders a feature with two scenarios', function () {
assertPrettyIdentical("Feature: hello\n\n Scenario: one\n Given hello\n\n Scenario: two\n Given world\n");
it('renders a feature with two scenarios', () => {
assertPrettyIdentical(`Feature: hello
Scenario: one
Given hello
Scenario: two
Given world
`);
});
it('renders a feature with two scenarios in a rule', function () {
assertPrettyIdentical("Feature: hello\n\n Rule: ok\n\n Scenario: one\n Given hello\n\n Scenario: two\n Given world\n");
it('renders a feature with two scenarios in a rule', () => {
assertPrettyIdentical(`Feature: hello
Rule: ok
Scenario: one
Given hello
Scenario: two
Given world
`);
});
it('renders a feature with background and scenario', function () {
assertPrettyIdentical("Feature: hello\n\n Background: bbb\n Given hello\n\n Scenario: two\n Given world\n");
it('renders a feature with background and scenario', () => {
assertPrettyIdentical(`Feature: hello
Background: bbb
Given hello
Scenario: two
Given world
`);
});
it('renders a rule with background and scenario', function () {
assertPrettyIdentical("Feature: hello\n\n Rule: machin\n\n Background: bbb\n Given hello\n\n Scenario: two\n Given world\n");
it('renders a rule with background and scenario', () => {
assertPrettyIdentical(`Feature: hello
Rule: machin
Background: bbb
Given hello
Scenario: two
Given world
`);
});
it('renders tags when set', function () {
assertPrettyIdentical("@featureTag\nFeature: hello\n\n Rule: machin\n\n Background: bbb\n Given hello\n\n @scenarioTag @secondTag\n Scenario: two\n Given world\n");
it('renders tags when set', () => {
assertPrettyIdentical(`@featureTag
Feature: hello
Rule: machin
Background: bbb
Given hello
@scenarioTag @secondTag
Scenario: two
Given world
`);
});
it('renders descriptions when set', function () {
assertPrettyIdentical("Feature: hello\n So this is a feature\n\n Rule: machin\n The first rule of the feature states things\n\n Background: bbb\n We can have some explications for the background\n\n Given hello\n\n Scenario: two\n This scenario will do things, maybe\n\n Given world\n");
it('renders descriptions when set', () => {
assertPrettyIdentical(`Feature: hello
So this is a feature
Rule: machin
The first rule of the feature states things
Background: bbb
We can have some explications for the background
Given hello
Scenario: two
This scenario will do things, maybe
Given world
`);
});
});
function assertPrettyIdentical(source) {
var gherkinDocument = parse_1.default(source);
const gherkinDocument = parse_1.default(source);
assert_1.default.strictEqual(pretty_1.default(gherkinDocument), source);
}
//# sourceMappingURL=prettyTest.js.map
export {};
//# sourceMappingURL=QueryTest.d.ts.map

@@ -11,29 +11,2 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -43,178 +16,159 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var GherkinStreams_1 = __importDefault(require("@cucumber/gherkin/dist/src/stream/GherkinStreams"));
var messages_1 = require("@cucumber/messages");
var stream_1 = require("stream");
var assert_1 = __importDefault(require("assert"));
var Query_1 = __importDefault(require("../src/Query"));
var util_1 = require("util");
var pipelinePromise = util_1.promisify(stream_1.pipeline);
describe('Query', function () {
var gherkinQuery;
var envelopes;
beforeEach(function () {
const gherkin_streams_1 = require("@cucumber/gherkin-streams");
const messages_1 = require("@cucumber/messages");
const stream_1 = require("stream");
const assert_1 = __importDefault(require("assert"));
const Query_1 = __importDefault(require("../src/Query"));
const util_1 = require("util");
const pipelinePromise = util_1.promisify(stream_1.pipeline);
describe('Query', () => {
let gherkinQuery;
let envelopes;
beforeEach(() => {
envelopes = [];
gherkinQuery = new Query_1.default();
});
describe('#getLocation(astNodeId)', function () {
it('looks up a scenario line number', function () { return __awaiter(void 0, void 0, void 0, function () {
var pickle, gherkinScenarioId, location;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Scenario: hi\n Given a passed step\n")];
case 1:
_a.sent();
pickle = envelopes.find(function (e) { return e.pickle; }).pickle;
gherkinScenarioId = pickle.astNodeIds[0];
location = gherkinQuery.getLocation(gherkinScenarioId);
assert_1.default.deepStrictEqual(location.line, 2);
return [2 /*return*/];
}
});
}); });
it('looks up a step line number', function () { return __awaiter(void 0, void 0, void 0, function () {
var pickleStep, gherkinStepId, location;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Scenario: hi\n Given a passed step\n")];
case 1:
_a.sent();
pickleStep = envelopes.find(function (e) { return e.pickle; }).pickle.steps[0];
gherkinStepId = pickleStep.astNodeIds[0];
location = gherkinQuery.getLocation(gherkinStepId);
assert_1.default.deepStrictEqual(location.line, 3);
return [2 /*return*/];
}
});
}); });
describe('#getLocation(astNodeId)', () => {
it('looks up a scenario line number', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Scenario: hi
Given a passed step
`);
const pickle = envelopes.find((e) => e.pickle).pickle;
const gherkinScenarioId = pickle.astNodeIds[0];
const location = gherkinQuery.getLocation(gherkinScenarioId);
assert_1.default.deepStrictEqual(location.line, 2);
}));
it('looks up a step line number', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Scenario: hi
Given a passed step
`);
const pickleStep = envelopes.find((e) => e.pickle).pickle.steps[0];
const gherkinStepId = pickleStep.astNodeIds[0];
const location = gherkinQuery.getLocation(gherkinStepId);
assert_1.default.deepStrictEqual(location.line, 3);
}));
});
describe('#getPickleIds(uri, astNodeId)', function () {
it('looks up pickle IDs for a scenario', function () { return __awaiter(void 0, void 0, void 0, function () {
var gherkinDocument, scenario, pickleId, pickleIds;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Background:\n Given a background step\n\n Scenario: hi\n Given a passed step\n")];
case 1:
_a.sent();
gherkinDocument = envelopes.find(function (envelope) { return envelope.gherkinDocument; }).gherkinDocument;
scenario = gherkinDocument.feature.children.find(function (child) { return child.scenario; }).scenario;
pickleId = envelopes.find(function (e) { return e.pickle; }).pickle.id;
pickleIds = gherkinQuery.getPickleIds('test.feature', scenario.id);
assert_1.default.deepStrictEqual(pickleIds, [pickleId]);
return [2 /*return*/];
}
describe('#getPickleIds(uri, astNodeId)', () => {
it('looks up pickle IDs for a scenario', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Background:
Given a background step
Scenario: hi
Given a passed step
`);
const gherkinDocument = envelopes.find((envelope) => envelope.gherkinDocument).gherkinDocument;
const scenario = gherkinDocument.feature.children.find((child) => child.scenario).scenario;
const pickleId = envelopes.find((e) => e.pickle).pickle.id;
const pickleIds = gherkinQuery.getPickleIds('test.feature', scenario.id);
assert_1.default.deepStrictEqual(pickleIds, [pickleId]);
}));
it('looks up pickle IDs for a whole document', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Scenario:
Given a failed step
Scenario: hi
Given a passed step
`);
const expectedPickleIds = envelopes.filter((e) => e.pickle).map((e) => e.pickle.id);
const pickleIds = gherkinQuery.getPickleIds('test.feature');
assert_1.default.deepStrictEqual(pickleIds, expectedPickleIds);
}));
it.skip('fails to look up pickle IDs for a step', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Background:
Given a background step
Scenario: hi
Given a passed step
`);
assert_1.default.throws(() => gherkinQuery.getPickleIds('test.feature', 'some-non-existing-id'), {
message: 'No values found for key 6. Keys: [some-non-existing-id]',
});
}); });
it('looks up pickle IDs for a whole document', function () { return __awaiter(void 0, void 0, void 0, function () {
var expectedPickleIds, pickleIds;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Scenario:\n Given a failed step\n\n Scenario: hi\n Given a passed step\n")];
case 1:
_a.sent();
expectedPickleIds = envelopes
.filter(function (e) { return e.pickle; })
.map(function (e) { return e.pickle.id; });
pickleIds = gherkinQuery.getPickleIds('test.feature');
assert_1.default.deepStrictEqual(pickleIds, expectedPickleIds);
return [2 /*return*/];
}
});
}); });
it.skip('fails to look up pickle IDs for a step', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Background:\n Given a background step\n\n Scenario: hi\n Given a passed step\n")];
case 1:
_a.sent();
assert_1.default.throws(function () { return gherkinQuery.getPickleIds('test.feature', 'some-non-existing-id'); }, {
message: 'No values found for key 6. Keys: [some-non-existing-id]',
});
return [2 /*return*/];
}
});
}); });
it('avoids dupes and ignores empty scenarios', function () { return __awaiter(void 0, void 0, void 0, function () {
var pickleIds;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: Examples and empty scenario\n\n Scenario: minimalistic\n Given the <what>\n\n Examples:\n | what |\n | foo |\n\n Examples:\n | what |\n | bar |\n\n Scenario: ha ok\n")];
case 1:
_a.sent();
pickleIds = gherkinQuery.getPickleIds('test.feature');
// One for each table, and one for the empty scenario
// https://github.com/cucumber/cucumber/issues/249
assert_1.default.strictEqual(pickleIds.length, 3, pickleIds.join(','));
return [2 /*return*/];
}
});
}); });
}));
it('avoids dupes and ignores empty scenarios', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: Examples and empty scenario
Scenario: minimalistic
Given the <what>
Examples:
| what |
| foo |
Examples:
| what |
| bar |
Scenario: ha ok
`);
const pickleIds = gherkinQuery.getPickleIds('test.feature');
// One for each table, and one for the empty scenario
// https://github.com/cucumber/cucumber/issues/249
assert_1.default.strictEqual(pickleIds.length, 3, pickleIds.join(','));
}));
});
describe('#getPickleStepIds(astNodeId', function () {
it('returns an empty list when the ID is unknown', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse('Feature: An empty feature')];
case 1:
_a.sent();
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds('whetever-id'), []);
return [2 /*return*/];
}
});
}); });
it('returns the pickle step IDs corresponding the a scenario step', function () { return __awaiter(void 0, void 0, void 0, function () {
var pickleStepIds, stepId;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Scenario:\n Given a failed step\n")];
case 1:
_a.sent();
pickleStepIds = envelopes
.find(function (envelope) { return envelope.pickle; })
.pickle.steps.map(function (pickleStep) { return pickleStep.id; });
stepId = envelopes.find(function (envelope) { return envelope.gherkinDocument; })
.gherkinDocument.feature.children[0].scenario.steps[0].id;
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds(stepId), pickleStepIds);
return [2 /*return*/];
}
});
}); });
context('when a step has multiple pickle step', function () {
it('returns all pickleStepIds linked to a background step', function () { return __awaiter(void 0, void 0, void 0, function () {
var backgroundStepId, pickleStepIds;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Background:\n Given a step that will have 2 pickle steps\n\n Scenario:\n Given a step that will only have 1 pickle step\n\n Scenario:\n Given a step that will only have 1 pickle step\n ")];
case 1:
_a.sent();
backgroundStepId = envelopes.find(function (envelope) { return envelope.gherkinDocument; }).gherkinDocument.feature.children[0].background.steps[0].id;
pickleStepIds = envelopes
.filter(function (envelope) { return envelope.pickle; })
.map(function (envelope) { return envelope.pickle.steps[0].id; });
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds(backgroundStepId), pickleStepIds);
return [2 /*return*/];
}
});
}); });
it('return all pickleStepIds linked to a step in a scenario with examples', function () { return __awaiter(void 0, void 0, void 0, function () {
var scenarioStepId, pickleStepIds;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, parse("Feature: hello\n Scenario:\n Given a passed step\n And a <status> step\n\n Examples:\n | status |\n | passed |\n | failed |\n")];
case 1:
_a.sent();
scenarioStepId = envelopes.find(function (envelope) { return envelope.gherkinDocument; }).gherkinDocument.feature.children[0].scenario.steps[1].id;
pickleStepIds = envelopes
.filter(function (envelope) { return envelope.pickle; })
.map(function (envelope) { return envelope.pickle.steps[1].id; });
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds(scenarioStepId), pickleStepIds);
return [2 /*return*/];
}
});
}); });
describe('#getPickleStepIds(astNodeId', () => {
it('returns an empty list when the ID is unknown', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse('Feature: An empty feature');
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds('whetever-id'), []);
}));
it('returns the pickle step IDs corresponding the a scenario step', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Scenario:
Given a failed step
`);
const pickleStepIds = envelopes
.find((envelope) => envelope.pickle)
.pickle.steps.map((pickleStep) => pickleStep.id);
const stepId = envelopes.find((envelope) => envelope.gherkinDocument).gherkinDocument.feature
.children[0].scenario.steps[0].id;
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds(stepId), pickleStepIds);
}));
context('when a step has multiple pickle step', () => {
it('returns all pickleStepIds linked to a background step', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Background:
Given a step that will have 2 pickle steps
Scenario:
Given a step that will only have 1 pickle step
Scenario:
Given a step that will only have 1 pickle step
`);
const backgroundStepId = envelopes.find((envelope) => envelope.gherkinDocument)
.gherkinDocument.feature.children[0].background.steps[0].id;
const pickleStepIds = envelopes
.filter((envelope) => envelope.pickle)
.map((envelope) => envelope.pickle.steps[0].id);
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds(backgroundStepId), pickleStepIds);
}));
it('return all pickleStepIds linked to a step in a scenario with examples', () => __awaiter(void 0, void 0, void 0, function* () {
yield parse(`Feature: hello
Scenario:
Given a passed step
And a <status> step
Examples:
| status |
| passed |
| failed |
`);
const scenarioStepId = envelopes.find((envelope) => envelope.gherkinDocument)
.gherkinDocument.feature.children[0].scenario.steps[1].id;
const pickleStepIds = envelopes
.filter((envelope) => envelope.pickle)
.map((envelope) => envelope.pickle.steps[1].id);
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds(scenarioStepId), pickleStepIds);
}));
});
});
function parse(gherkinSource) {
var writable = new stream_1.Writable({
const writable = new stream_1.Writable({
objectMode: true,
write: function (envelope, encoding, callback) {
write(envelope, encoding, callback) {
envelopes.push(envelope);

@@ -233,5 +187,5 @@ try {

function gherkinMessages(gherkinSource, uri) {
var source = messages_1.messages.Envelope.fromObject({
const source = messages_1.messages.Envelope.fromObject({
source: {
uri: uri,
uri,
data: gherkinSource,

@@ -241,6 +195,6 @@ mediaType: 'text/x.cucumber.gherkin+plain',

});
var newId = messages_1.IdGenerator.incrementing();
return GherkinStreams_1.default.fromSources([source], { newId: newId });
const newId = messages_1.IdGenerator.incrementing();
return gherkin_streams_1.GherkinStreams.fromSources([source], { newId });
}
});
//# sourceMappingURL=QueryTest.js.map
{
"name": "@cucumber/gherkin-utils",
"version": "3.0.0",
"version": "4.0.0",
"description": "Various Gherkin utilities",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"bin": {},
"scripts": {
"test": "mocha",
"lint": "eslint --ext ts --max-warnings 0 src test",
"lint-fix": "eslint --ext ts --max-warnings 0 --fix src test",
"coverage": "nyc --reporter=html --reporter=text mocha",
"build": "tsc",
"prepublishOnly": "npm run build"
"prepublishOnly": "tsc --build tsconfig.build.json"
},

@@ -30,24 +25,18 @@ "repository": {

"devDependencies": {
"@cucumber/gherkin": "^17.0.0",
"@cucumber/gherkin": "^18.0.0",
"@cucumber/gherkin-streams": "^1.0.0",
"@cucumber/message-streams": "^1.0.0",
"@types/glob": "^7.1.3",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.25",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"core-js": "^3.8.3",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"glob": "^7.1.6",
"mocha": "^8.2.1",
"mocha": "^8.3.2",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"typescript": "^4.2.3"
},
"dependencies": {
"@cucumber/messages": "^14.0.0",
"@cucumber/messages": "^15.0.0",
"@teppeis/multimaps": "^2.0.0"

@@ -54,0 +43,0 @@ },

import { messages } from '@cucumber/messages'
export interface IFilters {
acceptScenario?: (
scenario: messages.GherkinDocument.Feature.IScenario
) => boolean
acceptScenario?: (scenario: messages.GherkinDocument.Feature.IScenario) => boolean
acceptStep?: (step: messages.GherkinDocument.Feature.IStep) => boolean
acceptBackground?: (
background: messages.GherkinDocument.Feature.IBackground
) => boolean
acceptRule?: (
rule: messages.GherkinDocument.Feature.FeatureChild.IRule
) => boolean
acceptBackground?: (background: messages.GherkinDocument.Feature.IBackground) => boolean
acceptRule?: (rule: messages.GherkinDocument.Feature.FeatureChild.IRule) => boolean
acceptFeature?: (feature: messages.GherkinDocument.IFeature) => boolean

@@ -19,11 +13,5 @@ }

handleStep?: (step: messages.GherkinDocument.Feature.IStep) => void
handleScenario?: (
scenario: messages.GherkinDocument.Feature.IScenario
) => void
handleBackground?: (
background: messages.GherkinDocument.Feature.IBackground
) => void
handleRule?: (
rule: messages.GherkinDocument.Feature.FeatureChild.IRule
) => void
handleScenario?: (scenario: messages.GherkinDocument.Feature.IScenario) => void
handleBackground?: (background: messages.GherkinDocument.Feature.IBackground) => void
handleRule?: (rule: messages.GherkinDocument.Feature.FeatureChild.IRule) => void
handleFeature?: (feature: messages.GherkinDocument.IFeature) => void

@@ -156,11 +144,7 @@ }

const scenariosKeptById = new Map(
children
.filter((child) => child.scenario)
.map((child) => [child.scenario.id, child])
children.filter((child) => child.scenario).map((child) => [child.scenario.id, child])
)
const ruleKeptById = new Map(
children
.filter((child) => child.rule)
.map((child) => [child.rule.id, child])
children.filter((child) => child.rule).map((child) => [child.rule.id, child])
)

@@ -235,8 +219,4 @@

const backgroundKept = children.find(
(child) => child !== null && child.background !== null
)
const scenariosKept = children.filter(
(child) => child !== null && child.scenario !== null
)
const backgroundKept = children.find((child) => child !== null && child.background !== null)
const scenariosKept = children.filter((child) => child !== null && child.scenario !== null)

@@ -324,6 +304,3 @@ if (this.filters.acceptRule(rule) || backgroundKept) {

if (
this.filters.acceptBackground(background) ||
steps.find((step) => step !== null)
) {
if (this.filters.acceptBackground(background) || steps.find((step) => step !== null)) {
return this.copyBackground(background)

@@ -352,6 +329,3 @@ }

if (
this.filters.acceptScenario(scenario) ||
steps.find((step) => step !== null)
) {
if (this.filters.acceptScenario(scenario) || steps.find((step) => step !== null)) {
return this.copyScenario(scenario)

@@ -358,0 +332,0 @@ }

import pretty from './pretty'
import Query from './Query'
import GherkinDocumentWalker, {
rejectAllFilters,
} from './GherkinDocumentWalker'
import GherkinDocumentWalker, { rejectAllFilters } from './GherkinDocumentWalker'
export { pretty, Query, GherkinDocumentWalker, rejectAllFilters }
import { messages } from '@cucumber/messages'
export default function pretty(
gherkinDocument: messages.IGherkinDocument
): string {
export default function pretty(gherkinDocument: messages.IGherkinDocument): string {
const feature = gherkinDocument.feature

@@ -40,5 +38,5 @@ let s = prettyTags(feature.tags)

): string {
let s = `\n${prettyTags(stepContainer.tags, indent)}${indent}${
stepContainer.keyword
}: ${stepContainer.name}\n`
let s = `\n${prettyTags(stepContainer.tags, indent)}${indent}${stepContainer.keyword}: ${
stepContainer.name
}\n`
if (stepContainer.description) {

@@ -74,6 +72,3 @@ s += stepContainer.description + '\n\n'

function prettyTableRow(
row: messages.GherkinDocument.Feature.ITableRow,
indent: string
): string {
function prettyTableRow(row: messages.GherkinDocument.Feature.ITableRow, indent: string): string {
return `${indent}| ${row.cells.map((cell) => cell.value).join(' | ')} |\n`

@@ -80,0 +75,0 @@ }

@@ -8,10 +8,4 @@ import { messages } from '@cucumber/messages'

private readonly locationByAstNodeId = new Map<string, messages.ILocation>()
private readonly gherkinStepById = new Map<
string,
messages.GherkinDocument.Feature.IStep
>()
private readonly pickleIdsMapByUri = new Map<
string,
ArrayMultimap<string, string>
>()
private readonly gherkinStepById = new Map<string, messages.GherkinDocument.Feature.IStep>()
private readonly pickleIdsMapByUri = new Map<string, ArrayMultimap<string, string>>()

@@ -59,6 +53,3 @@ private readonly pickleIdsByAstNodeId = new Map<string, string[]>()

if (message.gherkinDocument.feature) {
this.pickleIdsMapByUri.set(
message.gherkinDocument.uri,
new ArrayMultimap<string, string>()
)
this.pickleIdsMapByUri.set(message.gherkinDocument.uri, new ArrayMultimap<string, string>())

@@ -98,5 +89,3 @@ for (const featureChild of message.gherkinDocument.feature.children) {

private updateGherkinBackground(
background: messages.GherkinDocument.Feature.IBackground
) {
private updateGherkinBackground(background: messages.GherkinDocument.Feature.IBackground) {
for (const step of background.steps) {

@@ -107,5 +96,3 @@ this.updateGherkinStep(step)

private updateGherkinScenario(
scenario: messages.GherkinDocument.Feature.IScenario
) {
private updateGherkinScenario(scenario: messages.GherkinDocument.Feature.IScenario) {
this.locationByAstNodeId.set(scenario.id, scenario.location)

@@ -112,0 +99,0 @@ for (const step of scenario.steps) {

import assert from 'assert'
import GherkinDocumentWalker, {
rejectAllFilters,
} from '../src/GherkinDocumentWalker'
import GherkinDocumentWalker, { rejectAllFilters } from '../src/GherkinDocumentWalker'
import pretty from '../src/pretty'

@@ -435,4 +433,3 @@ import parse from './parse'

{
handleBackground: (background) =>
backgroundName.push(background.name),
handleBackground: (background) => backgroundName.push(background.name),
}

@@ -439,0 +436,0 @@ )

import { messages } from '@cucumber/messages'
import { NdjsonToMessageStream } from '@cucumber/messages/dist/src/stream'
import { NdjsonToMessageStream } from '@cucumber/message-streams'
import { Writable, pipeline } from 'stream'

@@ -4,0 +4,0 @@

import { IdGenerator, messages } from '@cucumber/messages'
import { AstBuilder, Parser } from '@cucumber/gherkin'
import { AstBuilder, Parser, TokenMatcher } from '@cucumber/gherkin'
export default function parse(source: string): messages.IGherkinDocument {
const newId = IdGenerator.uuid()
const parser = new Parser(new AstBuilder(newId))
const parser = new Parser(new AstBuilder(newId), new TokenMatcher())
const gherkinDocument = parser.parse(source)

@@ -8,0 +8,0 @@ gherkinDocument.uri = ''

@@ -1,2 +0,2 @@

import GherkinStreams from '@cucumber/gherkin/dist/src/stream/GherkinStreams'
import { GherkinStreams } from '@cucumber/gherkin-streams'
import { IdGenerator, messages } from '@cucumber/messages'

@@ -58,8 +58,4 @@ import { pipeline, Readable, Writable } from 'stream'

const gherkinDocument = envelopes.find(
(envelope) => envelope.gherkinDocument
).gherkinDocument
const scenario = gherkinDocument.feature.children.find(
(child) => child.scenario
).scenario
const gherkinDocument = envelopes.find((envelope) => envelope.gherkinDocument).gherkinDocument
const scenario = gherkinDocument.feature.children.find((child) => child.scenario).scenario

@@ -81,5 +77,3 @@ const pickleId = envelopes.find((e) => e.pickle).pickle.id

)
const expectedPickleIds = envelopes
.filter((e) => e.pickle)
.map((e) => e.pickle.id)
const expectedPickleIds = envelopes.filter((e) => e.pickle).map((e) => e.pickle.id)
const pickleIds = gherkinQuery.getPickleIds('test.feature')

@@ -100,8 +94,5 @@ assert.deepStrictEqual(pickleIds, expectedPickleIds)

assert.throws(
() => gherkinQuery.getPickleIds('test.feature', 'some-non-existing-id'),
{
message: 'No values found for key 6. Keys: [some-non-existing-id]',
}
)
assert.throws(() => gherkinQuery.getPickleIds('test.feature', 'some-non-existing-id'), {
message: 'No values found for key 6. Keys: [some-non-existing-id]',
})
})

@@ -154,4 +145,4 @@

const stepId = envelopes.find((envelope) => envelope.gherkinDocument)
.gherkinDocument.feature.children[0].scenario.steps[0].id
const stepId = envelopes.find((envelope) => envelope.gherkinDocument).gherkinDocument.feature
.children[0].scenario.steps[0].id

@@ -176,5 +167,4 @@ assert.deepEqual(gherkinQuery.getPickleStepIds(stepId), pickleStepIds)

const backgroundStepId = envelopes.find(
(envelope) => envelope.gherkinDocument
).gherkinDocument.feature.children[0].background.steps[0].id
const backgroundStepId = envelopes.find((envelope) => envelope.gherkinDocument)
.gherkinDocument.feature.children[0].background.steps[0].id

@@ -185,6 +175,3 @@ const pickleStepIds = envelopes

assert.deepEqual(
gherkinQuery.getPickleStepIds(backgroundStepId),
pickleStepIds
)
assert.deepEqual(gherkinQuery.getPickleStepIds(backgroundStepId), pickleStepIds)
})

@@ -206,5 +193,4 @@

const scenarioStepId = envelopes.find(
(envelope) => envelope.gherkinDocument
).gherkinDocument.feature.children[0].scenario.steps[1].id
const scenarioStepId = envelopes.find((envelope) => envelope.gherkinDocument)
.gherkinDocument.feature.children[0].scenario.steps[1].id

@@ -215,6 +201,3 @@ const pickleStepIds = envelopes

assert.deepEqual(
gherkinQuery.getPickleStepIds(scenarioStepId),
pickleStepIds
)
assert.deepEqual(gherkinQuery.getPickleStepIds(scenarioStepId), pickleStepIds)
})

@@ -241,6 +224,3 @@ })

})
return pipelinePromise(
gherkinMessages(gherkinSource, 'test.feature'),
writable
)
return pipelinePromise(gherkinMessages(gherkinSource, 'test.feature'), writable)
}

@@ -247,0 +227,0 @@

{
"compilerOptions": {
"declaration": true,
"target": "es5",
"lib": [
"es2019",
"dom"
],
"sourceMap": true,
"allowJs": false,
"jsx": "react",
"resolveJsonModule": true,
"module": "commonjs",
"esModuleInterop": true,
"noImplicitAny": true,
"moduleResolution": "node",
"outDir": "dist",
"downlevelIteration": true,
"skipLibCheck": true
},
"include": [
"src/**/*",
"test/**/*",
"features/**/*"
]
"extends": "../../tsconfig.json"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc