Socket
Socket
Sign inDemoInstall

@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 4.0.0 to 5.0.0

36

dist/src/GherkinDocumentWalker.d.ts

@@ -1,15 +0,15 @@

import { messages } from '@cucumber/messages';
import * as messages from '@cucumber/messages';
export interface IFilters {
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;
acceptFeature?: (feature: messages.GherkinDocument.IFeature) => boolean;
acceptScenario?: (scenario: messages.Scenario) => boolean;
acceptStep?: (step: messages.Step) => boolean;
acceptBackground?: (background: messages.Background) => boolean;
acceptRule?: (rule: messages.Rule) => boolean;
acceptFeature?: (feature: messages.Feature) => boolean;
}
export interface IHandlers {
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;
handleFeature?: (feature: messages.GherkinDocument.IFeature) => void;
handleStep?: (step: messages.Step) => void;
handleScenario?: (scenario: messages.Scenario) => void;
handleBackground?: (background: messages.Background) => void;
handleRule?: (rule: messages.Rule) => void;
handleFeature?: (feature: messages.Feature) => void;
}

@@ -21,4 +21,4 @@ export declare const rejectAllFilters: IFilters;

constructor(filters?: IFilters, handlers?: IHandlers);
walkGherkinDocument(gherkinDocument: messages.IGherkinDocument): messages.IGherkinDocument;
protected walkFeature(feature: messages.GherkinDocument.IFeature): messages.GherkinDocument.IFeature;
walkGherkinDocument(gherkinDocument: messages.GherkinDocument): messages.GherkinDocument | null;
protected walkFeature(feature: messages.Feature): messages.Feature;
private copyFeature;

@@ -28,14 +28,14 @@ private copyTags;

private walkFeatureChildren;
protected walkRule(rule: messages.GherkinDocument.Feature.FeatureChild.IRule): messages.GherkinDocument.Feature.FeatureChild.IRule;
protected walkRule(rule: messages.Rule): messages.Rule;
private copyRule;
private filterRuleChildren;
private walkRuleChildren;
protected walkBackground(background: messages.GherkinDocument.Feature.IBackground): messages.GherkinDocument.Feature.IBackground;
protected walkBackground(background: messages.Background): messages.Background;
private copyBackground;
protected walkScenario(scenario: messages.GherkinDocument.Feature.IScenario): messages.GherkinDocument.Feature.IScenario;
protected walkScenario(scenario: messages.Scenario): messages.Scenario;
private copyScenario;
protected walkAllSteps(steps: messages.GherkinDocument.Feature.IStep[]): messages.GherkinDocument.Feature.IStep[];
protected walkStep(step: messages.GherkinDocument.Feature.IStep): messages.GherkinDocument.Feature.IStep;
protected walkAllSteps(steps: readonly messages.Step[]): messages.Step[];
protected walkStep(step: messages.Step): messages.Step;
private copyStep;
}
//# sourceMappingURL=GherkinDocumentWalker.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rejectAllFilters = void 0;
const messages_1 = require("@cucumber/messages");
const defaultFilters = {

@@ -39,7 +38,7 @@ acceptScenario: () => true,

}
return messages_1.messages.GherkinDocument.create({
feature: feature,
return {
feature,
comments: gherkinDocument.comments,
uri: gherkinDocument.uri,
});
};
}

@@ -53,15 +52,15 @@ walkFeature(feature) {

if (child.background) {
return messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
return {
background: this.copyBackground(child.background),
});
};
}
if (child.scenario) {
return messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
return {
scenario: this.copyScenario(child.scenario),
});
};
}
if (child.rule) {
return messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
return {
rule: this.copyRule(child.rule, child.rule.children),
});
};
}

@@ -75,3 +74,3 @@ }));

copyFeature(feature, children) {
return messages_1.messages.GherkinDocument.Feature.create({
return {
children: this.filterFeatureChildren(feature, children),

@@ -82,8 +81,8 @@ location: feature.location,

name: feature.name,
description: feature.description ? feature.description : undefined,
description: feature.description,
tags: this.copyTags(feature.tags),
});
};
}
copyTags(tags) {
return tags.map((tag) => messages_1.messages.GherkinDocument.Feature.Tag.create({
return tags.map((tag) => ({
name: tag.name,

@@ -100,5 +99,5 @@ id: tag.id,

if (child.background) {
copyChildren.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
copyChildren.push({
background: this.copyBackground(child.background),
}));
});
}

@@ -136,7 +135,7 @@ if (child.scenario) {

if (backgroundCopy || scenarioCopy || ruleCopy) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({
childrenCopy.push({
background: backgroundCopy,
scenario: scenarioCopy,
rule: ruleCopy,
}));
});
}

@@ -159,10 +158,11 @@ }

copyRule(rule, children) {
return messages_1.messages.GherkinDocument.Feature.FeatureChild.Rule.create({
return {
id: rule.id,
name: rule.name,
description: rule.description ? rule.description : undefined,
description: rule.description,
location: rule.location,
keyword: rule.keyword,
children: this.filterRuleChildren(rule.children, children),
});
tags: this.copyTags(rule.tags),
};
}

@@ -176,10 +176,10 @@ filterRuleChildren(children, childrenKept) {

if (child.background) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
childrenCopy.push({
background: this.copyBackground(child.background),
}));
});
}
if (child.scenario && scenariosKeptIds.includes(child.scenario.id)) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
childrenCopy.push({
scenario: this.copyScenario(child.scenario),
}));
});
}

@@ -193,10 +193,10 @@ }

if (child.background) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
childrenCopy.push({
background: this.walkBackground(child.background),
}));
});
}
if (child.scenario) {
childrenCopy.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
childrenCopy.push({
scenario: this.walkScenario(child.scenario),
}));
});
}

@@ -214,3 +214,3 @@ }

copyBackground(background) {
return messages_1.messages.GherkinDocument.Feature.Background.create({
return {
id: background.id,

@@ -221,4 +221,4 @@ name: background.name,

steps: background.steps.map((step) => this.copyStep(step)),
description: background.description ? background.description : undefined,
});
description: background.description,
};
}

@@ -233,6 +233,6 @@ walkScenario(scenario) {

copyScenario(scenario) {
return messages_1.messages.GherkinDocument.Feature.Scenario.create({
return {
id: scenario.id,
name: scenario.name,
description: scenario.description ? scenario.description : undefined,
description: scenario.description,
location: scenario.location,

@@ -243,3 +243,3 @@ keyword: scenario.keyword,

tags: this.copyTags(scenario.tags),
});
};
}

@@ -257,3 +257,3 @@ walkAllSteps(steps) {

copyStep(step) {
return messages_1.messages.GherkinDocument.Feature.Step.create({
return {
id: step.id,

@@ -265,3 +265,3 @@ keyword: step.keyword,

docString: step.docString,
});
};
}

@@ -268,0 +268,0 @@ }

@@ -1,3 +0,3 @@

import { messages } from '@cucumber/messages';
export default function pretty(gherkinDocument: messages.IGherkinDocument): string;
import * as messages from '@cucumber/messages';
export default function pretty(gherkinDocument: messages.GherkinDocument): string;
//# sourceMappingURL=pretty.d.ts.map

@@ -36,3 +36,5 @@ "use strict";

function prettyStepContainer(stepContainer, indent) {
let s = `\n${prettyTags(stepContainer.tags, indent)}${indent}${stepContainer.keyword}: ${stepContainer.name}\n`;
const scenario = 'tags' in stepContainer ? stepContainer : null;
const tags = (scenario === null || scenario === void 0 ? void 0 : scenario.tags) || [];
let s = `\n${prettyTags(tags, indent)}${indent}${stepContainer.keyword}: ${stepContainer.name}\n`;
if (stepContainer.description) {

@@ -44,4 +46,4 @@ s += stepContainer.description + '\n\n';

}
if (stepContainer.examples) {
for (const example of stepContainer.examples) {
if (scenario) {
for (const example of scenario.examples) {
s += prettyExample(example, `${indent} `);

@@ -48,0 +50,0 @@ }

@@ -1,10 +0,12 @@

import { messages } from '@cucumber/messages';
import * as messages from '@cucumber/messages';
export default class Query {
private readonly sources;
private readonly gherkinDocuments;
private readonly pickles;
private readonly locationByAstNodeId;
private readonly gherkinStepById;
private readonly gherkinStepByAstNodeId;
private readonly pickleIdsMapByUri;
private readonly pickleIdsByAstNodeId;
private readonly pickleStepIdsByAstNodeId;
private readonly stepByUriLocation;
/**

@@ -14,13 +16,15 @@ * Gets the location (line and column) of an AST node.

*/
getLocation(astNodeId: string): messages.ILocation;
getGherkinDocuments(): ReadonlyArray<messages.IGherkinDocument>;
getPickles(): ReadonlyArray<messages.IPickle>;
getLocation(astNodeId: string): messages.Location;
getSources(): readonly messages.Source[];
getGherkinDocuments(): readonly messages.GherkinDocument[];
getPickles(): readonly messages.Pickle[];
getStep(uri: string, line: number): messages.Step | undefined;
/**
* Gets all the pickle IDs
* @param uri - the URI of the document
* @param lineNumber - optionally restrict results to a particular line number
* @param astNodeId - optionally restrict results to a particular AST node
*/
getPickleIds(uri: string, astNodeId?: string): ReadonlyArray<string>;
getPickleStepIds(astNodeId: string): ReadonlyArray<string>;
update(message: messages.IEnvelope): Query;
getPickleIds(uri: string, astNodeId?: string): readonly string[];
getPickleStepIds(astNodeId: string): readonly string[];
update(message: messages.Envelope): Query;
private updateGherkinBackground;

@@ -27,0 +31,0 @@ private updateGherkinScenario;

@@ -6,9 +6,11 @@ "use strict";

constructor() {
this.sources = [];
this.gherkinDocuments = [];
this.pickles = [];
this.locationByAstNodeId = new Map();
this.gherkinStepById = new Map();
this.gherkinStepByAstNodeId = new Map();
this.pickleIdsMapByUri = new Map();
this.pickleIdsByAstNodeId = new Map();
this.pickleStepIdsByAstNodeId = new Map();
this.stepByUriLocation = new Map();
}

@@ -22,2 +24,5 @@ /**

}
getSources() {
return this.sources;
}
getGherkinDocuments() {

@@ -29,6 +34,9 @@ return this.gherkinDocuments;

}
getStep(uri, line) {
return this.stepByUriLocation.get([uri, line].join(':'));
}
/**
* Gets all the pickle IDs
* @param uri - the URI of the document
* @param lineNumber - optionally restrict results to a particular line number
* @param astNodeId - optionally restrict results to a particular AST node
*/

@@ -45,2 +53,5 @@ getPickleIds(uri, astNodeId) {

update(message) {
if (message.source) {
this.sources.push(message.source);
}
if (message.gherkinDocument) {

@@ -52,6 +63,6 @@ this.gherkinDocuments.push(message.gherkinDocument);

if (featureChild.background) {
this.updateGherkinBackground(featureChild.background);
this.updateGherkinBackground(message.gherkinDocument.uri, featureChild.background);
}
if (featureChild.scenario) {
this.updateGherkinScenario(featureChild.scenario);
this.updateGherkinScenario(message.gherkinDocument.uri, featureChild.scenario);
}

@@ -62,6 +73,6 @@ if (featureChild.rule) {

if (ruleChild.background) {
this.updateGherkinBackground(ruleChild.background);
this.updateGherkinBackground(message.gherkinDocument.uri, ruleChild.background);
}
if (ruleChild.scenario) {
this.updateGherkinScenario(ruleChild.scenario);
this.updateGherkinScenario(message.gherkinDocument.uri, ruleChild.scenario);
}

@@ -79,14 +90,14 @@ }

}
updateGherkinBackground(background) {
updateGherkinBackground(uri, background) {
for (const step of background.steps) {
this.updateGherkinStep(step);
this.updateGherkinStep(uri, step);
}
}
updateGherkinScenario(scenario) {
updateGherkinScenario(uri, scenario) {
this.locationByAstNodeId.set(scenario.id, scenario.location);
for (const step of scenario.steps) {
this.updateGherkinStep(step);
this.updateGherkinStep(uri, step);
}
for (const examples of scenario.examples) {
for (const tableRow of examples.tableBody) {
for (const tableRow of examples.tableBody || []) {
this.locationByAstNodeId.set(tableRow.id, tableRow.location);

@@ -96,5 +107,7 @@ }

}
updateGherkinStep(step) {
updateGherkinStep(uri, step) {
this.locationByAstNodeId.set(step.id, step.location);
this.gherkinStepById.set(step.id, step);
this.gherkinStepByAstNodeId.set(step.id, step);
const uriLocation = [uri, step.location.line].join(':');
this.stepByUriLocation.set(uriLocation, step);
}

@@ -101,0 +114,0 @@ updatePickle(pickle) {

@@ -51,2 +51,3 @@ "use strict";

@ruleTag
Rule: roule

@@ -138,3 +139,4 @@ Can we describe a Rule ?

});
it('keeps a hit background', () => {
// TODO before merging https://github.com/cucumber/cucumber/pull/1419
xit('keeps a hit background', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System

@@ -204,3 +206,4 @@

});
it('keeps scenario in rule', () => {
// TODO before merging https://github.com/cucumber/cucumber/pull/1419
xit('keeps scenario in rule', () => {
const gherkinDocument = parse_1.default(`Feature: Solar System

@@ -207,0 +210,0 @@

@@ -15,3 +15,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const messages_1 = require("@cucumber/messages");
const message_streams_1 = require("@cucumber/message-streams");

@@ -30,3 +29,3 @@ const stream_1 = require("stream");

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));
const messageStream = new message_streams_1.NdjsonToMessageStream();
yield asyncPipeline(fs_1.default.createReadStream(messageFile, 'utf-8'), messageStream, new stream_1.Writable({

@@ -33,0 +32,0 @@ objectMode: true,

@@ -1,3 +0,3 @@

import { messages } from '@cucumber/messages';
export default function parse(source: string): messages.IGherkinDocument;
import * as messages from '@cucumber/messages';
export default function parse(source: string): messages.GherkinDocument;
//# sourceMappingURL=parse.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const messages_1 = require("@cucumber/messages");
const messages = __importStar(require("@cucumber/messages"));
const gherkin_1 = require("@cucumber/gherkin");
function parse(source) {
const newId = messages_1.IdGenerator.uuid();
const parser = new gherkin_1.Parser(new gherkin_1.AstBuilder(newId), new gherkin_1.TokenMatcher());
const newId = messages.IdGenerator.uuid();
const parser = new gherkin_1.Parser(new gherkin_1.AstBuilder(newId), new gherkin_1.GherkinClassicTokenMatcher());
const gherkinDocument = parser.parse(source);

@@ -9,0 +28,0 @@ gherkinDocument.uri = '';

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -16,3 +35,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

const gherkin_streams_1 = require("@cucumber/gherkin-streams");
const messages_1 = require("@cucumber/messages");
const messages = __importStar(require("@cucumber/messages"));
const stream_1 = require("stream");

@@ -116,3 +135,3 @@ const assert_1 = __importDefault(require("assert"));

yield parse('Feature: An empty feature');
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds('whetever-id'), []);
assert_1.default.deepEqual(gherkinQuery.getPickleStepIds('whatever-id'), []);
}));

@@ -187,10 +206,10 @@ it('returns the pickle step IDs corresponding the a scenario step', () => __awaiter(void 0, void 0, void 0, function* () {

function gherkinMessages(gherkinSource, uri) {
const source = messages_1.messages.Envelope.fromObject({
const source = {
source: {
uri,
data: gherkinSource,
mediaType: 'text/x.cucumber.gherkin+plain',
mediaType: messages.SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
},
});
const newId = messages_1.IdGenerator.incrementing();
};
const newId = messages.IdGenerator.incrementing();
return gherkin_streams_1.GherkinStreams.fromSources([source], { newId });

@@ -197,0 +216,0 @@ }

{
"name": "@cucumber/gherkin-utils",
"version": "4.0.0",
"version": "5.0.0",
"description": "Various Gherkin utilities",

@@ -25,19 +25,16 @@ "main": "dist/src/index.js",

"devDependencies": {
"@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.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.3.2",
"nyc": "^15.1.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
"@cucumber/gherkin": "19.0.0",
"@cucumber/gherkin-streams": "2.0.0",
"@cucumber/message-streams": "1.0.0",
"@types/glob": "7.1.3",
"@types/mocha": "8.2.2",
"@types/node": "15.3.0",
"glob": "7.1.7",
"mocha": "8.4.0",
"ts-node": "9.1.1",
"typescript": "4.2.4"
},
"dependencies": {
"@cucumber/messages": "^15.0.0",
"@teppeis/multimaps": "^2.0.0"
"@cucumber/messages": "16.0.0",
"@teppeis/multimaps": "2.0.0"
},

@@ -44,0 +41,0 @@ "directories": {

@@ -1,17 +0,17 @@

import { messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
export interface IFilters {
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
acceptFeature?: (feature: messages.GherkinDocument.IFeature) => boolean
acceptScenario?: (scenario: messages.Scenario) => boolean
acceptStep?: (step: messages.Step) => boolean
acceptBackground?: (background: messages.Background) => boolean
acceptRule?: (rule: messages.Rule) => boolean
acceptFeature?: (feature: messages.Feature) => boolean
}
export interface IHandlers {
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
handleFeature?: (feature: messages.GherkinDocument.IFeature) => void
handleStep?: (step: messages.Step) => void
handleScenario?: (scenario: messages.Scenario) => void
handleBackground?: (background: messages.Background) => void
handleRule?: (rule: messages.Rule) => void
handleFeature?: (feature: messages.Feature) => void
}

@@ -53,4 +53,4 @@

public walkGherkinDocument(
gherkinDocument: messages.IGherkinDocument
): messages.IGherkinDocument {
gherkinDocument: messages.GherkinDocument
): messages.GherkinDocument | null {
if (!gherkinDocument.feature) {

@@ -66,12 +66,10 @@ return null

return messages.GherkinDocument.create({
feature: feature,
return {
feature,
comments: gherkinDocument.comments,
uri: gherkinDocument.uri,
})
}
}
protected walkFeature(
feature: messages.GherkinDocument.IFeature
): messages.GherkinDocument.IFeature {
protected walkFeature(feature: messages.Feature): messages.Feature {
const keptChildren = this.walkFeatureChildren(feature.children)

@@ -88,15 +86,15 @@

if (child.background) {
return messages.GherkinDocument.Feature.FeatureChild.create({
return {
background: this.copyBackground(child.background),
})
}
}
if (child.scenario) {
return messages.GherkinDocument.Feature.FeatureChild.create({
return {
scenario: this.copyScenario(child.scenario),
})
}
}
if (child.rule) {
return messages.GherkinDocument.Feature.FeatureChild.create({
return {
rule: this.copyRule(child.rule, child.rule.children),
})
}
}

@@ -113,6 +111,6 @@ })

private copyFeature(
feature: messages.GherkinDocument.IFeature,
children: messages.GherkinDocument.Feature.IFeatureChild[]
): messages.GherkinDocument.IFeature {
return messages.GherkinDocument.Feature.create({
feature: messages.Feature,
children: messages.FeatureChild[]
): messages.Feature {
return {
children: this.filterFeatureChildren(feature, children),

@@ -123,24 +121,20 @@ location: feature.location,

name: feature.name,
description: feature.description ? feature.description : undefined,
description: feature.description,
tags: this.copyTags(feature.tags),
})
}
}
private copyTags(
tags: ReadonlyArray<messages.GherkinDocument.Feature.ITag>
): messages.GherkinDocument.Feature.ITag[] {
return tags.map((tag) =>
messages.GherkinDocument.Feature.Tag.create({
name: tag.name,
id: tag.id,
location: tag.location,
})
)
private copyTags(tags: readonly messages.Tag[]): messages.Tag[] {
return tags.map((tag) => ({
name: tag.name,
id: tag.id,
location: tag.location,
}))
}
private filterFeatureChildren(
feature: messages.GherkinDocument.IFeature,
children: messages.GherkinDocument.Feature.IFeatureChild[]
): messages.GherkinDocument.Feature.IFeatureChild[] {
const copyChildren: messages.GherkinDocument.Feature.IFeatureChild[] = []
feature: messages.Feature,
children: messages.FeatureChild[]
): messages.FeatureChild[] {
const copyChildren: messages.FeatureChild[] = []

@@ -157,7 +151,5 @@ const scenariosKeptById = new Map(

if (child.background) {
copyChildren.push(
messages.GherkinDocument.Feature.FeatureChild.create({
background: this.copyBackground(child.background),
})
)
copyChildren.push({
background: this.copyBackground(child.background),
})
}

@@ -182,11 +174,9 @@

private walkFeatureChildren(
children: messages.GherkinDocument.Feature.IFeatureChild[]
): messages.GherkinDocument.Feature.IFeatureChild[] {
const childrenCopy: messages.GherkinDocument.Feature.IFeatureChild[] = []
private walkFeatureChildren(children: readonly messages.FeatureChild[]): messages.FeatureChild[] {
const childrenCopy: messages.FeatureChild[] = []
for (const child of children) {
let backgroundCopy: messages.GherkinDocument.Feature.IBackground = null
let scenarioCopy: messages.GherkinDocument.Feature.IScenario = null
let ruleCopy: messages.GherkinDocument.Feature.FeatureChild.IRule = null
let backgroundCopy: messages.Background = null
let scenarioCopy: messages.Scenario = null
let ruleCopy: messages.Rule = null

@@ -204,9 +194,7 @@ if (child.background) {

if (backgroundCopy || scenarioCopy || ruleCopy) {
childrenCopy.push(
messages.GherkinDocument.Feature.FeatureChild.create({
background: backgroundCopy,
scenario: scenarioCopy,
rule: ruleCopy,
})
)
childrenCopy.push({
background: backgroundCopy,
scenario: scenarioCopy,
rule: ruleCopy,
})
}

@@ -218,5 +206,3 @@ }

protected walkRule(
rule: messages.GherkinDocument.Feature.FeatureChild.IRule
): messages.GherkinDocument.Feature.FeatureChild.IRule {
protected walkRule(rule: messages.Rule): messages.Rule {
const children = this.walkRuleChildren(rule.children)

@@ -237,21 +223,19 @@

private copyRule(
rule: messages.GherkinDocument.Feature.FeatureChild.IRule,
children: messages.GherkinDocument.Feature.FeatureChild.IRuleChild[]
): messages.GherkinDocument.Feature.FeatureChild.IRule {
return messages.GherkinDocument.Feature.FeatureChild.Rule.create({
private copyRule(rule: messages.Rule, children: readonly messages.RuleChild[]): messages.Rule {
return {
id: rule.id,
name: rule.name,
description: rule.description ? rule.description : undefined,
description: rule.description,
location: rule.location,
keyword: rule.keyword,
children: this.filterRuleChildren(rule.children, children),
})
tags: this.copyTags(rule.tags),
}
}
private filterRuleChildren(
children: messages.GherkinDocument.Feature.FeatureChild.IRuleChild[],
childrenKept: messages.GherkinDocument.Feature.FeatureChild.IRuleChild[]
): messages.GherkinDocument.Feature.FeatureChild.IRuleChild[] {
const childrenCopy: messages.GherkinDocument.Feature.FeatureChild.IRuleChild[] = []
children: readonly messages.RuleChild[],
childrenKept: readonly messages.RuleChild[]
): messages.RuleChild[] {
const childrenCopy: messages.RuleChild[] = []
const scenariosKeptIds = childrenKept

@@ -263,14 +247,10 @@ .filter((child) => child.scenario)

if (child.background) {
childrenCopy.push(
messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
background: this.copyBackground(child.background),
})
)
childrenCopy.push({
background: this.copyBackground(child.background),
})
}
if (child.scenario && scenariosKeptIds.includes(child.scenario.id)) {
childrenCopy.push(
messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
scenario: this.copyScenario(child.scenario),
})
)
childrenCopy.push({
scenario: this.copyScenario(child.scenario),
})
}

@@ -282,21 +262,15 @@ }

private walkRuleChildren(
children: messages.GherkinDocument.Feature.FeatureChild.IRuleChild[]
): messages.GherkinDocument.Feature.FeatureChild.IRuleChild[] {
const childrenCopy: messages.GherkinDocument.Feature.FeatureChild.IRuleChild[] = []
private walkRuleChildren(children: readonly messages.RuleChild[]): messages.RuleChild[] {
const childrenCopy: messages.RuleChild[] = []
for (const child of children) {
if (child.background) {
childrenCopy.push(
messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
background: this.walkBackground(child.background),
})
)
childrenCopy.push({
background: this.walkBackground(child.background),
})
}
if (child.scenario) {
childrenCopy.push(
messages.GherkinDocument.Feature.FeatureChild.RuleChild.create({
scenario: this.walkScenario(child.scenario),
})
)
childrenCopy.push({
scenario: this.walkScenario(child.scenario),
})
}

@@ -307,5 +281,3 @@ }

protected walkBackground(
background: messages.GherkinDocument.Feature.IBackground
): messages.GherkinDocument.Feature.IBackground {
protected walkBackground(background: messages.Background): messages.Background {
const steps = this.walkAllSteps(background.steps)

@@ -319,6 +291,4 @@ this.handlers.handleBackground(background)

private copyBackground(
background: messages.GherkinDocument.Feature.IBackground
): messages.GherkinDocument.Feature.IBackground {
return messages.GherkinDocument.Feature.Background.create({
private copyBackground(background: messages.Background): messages.Background {
return {
id: background.id,

@@ -329,9 +299,7 @@ name: background.name,

steps: background.steps.map((step) => this.copyStep(step)),
description: background.description ? background.description : undefined,
})
description: background.description,
}
}
protected walkScenario(
scenario: messages.GherkinDocument.Feature.IScenario
): messages.GherkinDocument.Feature.IScenario {
protected walkScenario(scenario: messages.Scenario): messages.Scenario {
const steps = this.walkAllSteps(scenario.steps)

@@ -345,9 +313,7 @@ this.handlers.handleScenario(scenario)

private copyScenario(
scenario: messages.GherkinDocument.Feature.IScenario
): messages.GherkinDocument.Feature.IScenario {
return messages.GherkinDocument.Feature.Scenario.create({
private copyScenario(scenario: messages.Scenario): messages.Scenario {
return {
id: scenario.id,
name: scenario.name,
description: scenario.description ? scenario.description : undefined,
description: scenario.description,
location: scenario.location,

@@ -358,14 +324,10 @@ keyword: scenario.keyword,

tags: this.copyTags(scenario.tags),
})
}
}
protected walkAllSteps(
steps: messages.GherkinDocument.Feature.IStep[]
): messages.GherkinDocument.Feature.IStep[] {
protected walkAllSteps(steps: readonly messages.Step[]): messages.Step[] {
return steps.map((step) => this.walkStep(step))
}
protected walkStep(
step: messages.GherkinDocument.Feature.IStep
): messages.GherkinDocument.Feature.IStep {
protected walkStep(step: messages.Step): messages.Step {
this.handlers.handleStep(step)

@@ -378,6 +340,4 @@ if (!this.filters.acceptStep(step)) {

private copyStep(
step: messages.GherkinDocument.Feature.IStep
): messages.GherkinDocument.Feature.IStep {
return messages.GherkinDocument.Feature.Step.create({
private copyStep(step: messages.Step): messages.Step {
return {
id: step.id,

@@ -389,4 +349,4 @@ keyword: step.keyword,

docString: step.docString,
})
}
}
}

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

import { messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
export default function pretty(gherkinDocument: messages.IGherkinDocument): string {
export default function pretty(gherkinDocument: messages.GherkinDocument): string {
const feature = gherkinDocument.feature

@@ -35,8 +35,8 @@ let s = prettyTags(feature.tags)

function prettyStepContainer(
stepContainer: messages.GherkinDocument.Feature.IScenario,
stepContainer: messages.Scenario | messages.Background,
indent: string
): string {
let s = `\n${prettyTags(stepContainer.tags, indent)}${indent}${stepContainer.keyword}: ${
stepContainer.name
}\n`
const scenario: messages.Scenario = 'tags' in stepContainer ? stepContainer : null
const tags: readonly messages.Tag[] = scenario?.tags || []
let s = `\n${prettyTags(tags, indent)}${indent}${stepContainer.keyword}: ${stepContainer.name}\n`
if (stepContainer.description) {

@@ -50,4 +50,4 @@ s += stepContainer.description + '\n\n'

if (stepContainer.examples) {
for (const example of stepContainer.examples) {
if (scenario) {
for (const example of scenario.examples) {
s += prettyExample(example, `${indent} `)

@@ -59,6 +59,3 @@ }

function prettyExample(
example: messages.GherkinDocument.Feature.Scenario.IExamples,
indent: string
): string {
function prettyExample(example: messages.Examples, indent: string): string {
let s = `\n${indent}Examples: ${example.name}\n`

@@ -74,10 +71,7 @@

function prettyTableRow(row: messages.GherkinDocument.Feature.ITableRow, indent: string): string {
function prettyTableRow(row: messages.TableRow, indent: string): string {
return `${indent}| ${row.cells.map((cell) => cell.value).join(' | ')} |\n`
}
function prettyTags(
tags: ReadonlyArray<messages.GherkinDocument.Feature.ITag>,
indent = ''
): string {
function prettyTags(tags: readonly messages.Tag[], indent = ''): string {
if (tags === undefined || tags.length == 0) {

@@ -84,0 +78,0 @@ return ''

@@ -1,14 +0,14 @@

import { messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
import { ArrayMultimap } from '@teppeis/multimaps'
export default class Query {
private readonly gherkinDocuments: messages.IGherkinDocument[] = []
private readonly pickles: messages.IPickle[] = []
private readonly locationByAstNodeId = new Map<string, messages.ILocation>()
private readonly gherkinStepById = new Map<string, messages.GherkinDocument.Feature.IStep>()
private readonly sources: messages.Source[] = []
private readonly gherkinDocuments: messages.GherkinDocument[] = []
private readonly pickles: messages.Pickle[] = []
private readonly locationByAstNodeId = new Map<string, messages.Location>()
private readonly gherkinStepByAstNodeId = new Map<string, messages.Step>()
private readonly pickleIdsMapByUri = new Map<string, ArrayMultimap<string, string>>()
private readonly pickleIdsByAstNodeId = new Map<string, string[]>()
private readonly pickleStepIdsByAstNodeId = new Map<string, string[]>()
private readonly stepByUriLocation = new Map<string, messages.Step>()

@@ -19,20 +19,28 @@ /**

*/
public getLocation(astNodeId: string): messages.ILocation {
public getLocation(astNodeId: string): messages.Location {
return this.locationByAstNodeId.get(astNodeId)
}
public getGherkinDocuments(): ReadonlyArray<messages.IGherkinDocument> {
public getSources(): readonly messages.Source[] {
return this.sources
}
public getGherkinDocuments(): readonly messages.GherkinDocument[] {
return this.gherkinDocuments
}
public getPickles(): ReadonlyArray<messages.IPickle> {
public getPickles(): readonly messages.Pickle[] {
return this.pickles
}
public getStep(uri: string, line: number): messages.Step | undefined {
return this.stepByUriLocation.get([uri, line].join(':'))
}
/**
* Gets all the pickle IDs
* @param uri - the URI of the document
* @param lineNumber - optionally restrict results to a particular line number
* @param astNodeId - optionally restrict results to a particular AST node
*/
public getPickleIds(uri: string, astNodeId?: string): ReadonlyArray<string> {
public getPickleIds(uri: string, astNodeId?: string): readonly string[] {
const pickleIdsByAstNodeId = this.pickleIdsMapByUri.get(uri)

@@ -44,7 +52,11 @@ return astNodeId === undefined

public getPickleStepIds(astNodeId: string): ReadonlyArray<string> {
public getPickleStepIds(astNodeId: string): readonly string[] {
return this.pickleStepIdsByAstNodeId.get(astNodeId) || []
}
public update(message: messages.IEnvelope): Query {
public update(message: messages.Envelope): Query {
if (message.source) {
this.sources.push(message.source)
}
if (message.gherkinDocument) {

@@ -58,7 +70,7 @@ this.gherkinDocuments.push(message.gherkinDocument)

if (featureChild.background) {
this.updateGherkinBackground(featureChild.background)
this.updateGherkinBackground(message.gherkinDocument.uri, featureChild.background)
}
if (featureChild.scenario) {
this.updateGherkinScenario(featureChild.scenario)
this.updateGherkinScenario(message.gherkinDocument.uri, featureChild.scenario)
}

@@ -70,7 +82,7 @@

if (ruleChild.background) {
this.updateGherkinBackground(ruleChild.background)
this.updateGherkinBackground(message.gherkinDocument.uri, ruleChild.background)
}
if (ruleChild.scenario) {
this.updateGherkinScenario(ruleChild.scenario)
this.updateGherkinScenario(message.gherkinDocument.uri, ruleChild.scenario)
}

@@ -91,16 +103,16 @@ }

private updateGherkinBackground(background: messages.GherkinDocument.Feature.IBackground) {
private updateGherkinBackground(uri: string, background: messages.Background) {
for (const step of background.steps) {
this.updateGherkinStep(step)
this.updateGherkinStep(uri, step)
}
}
private updateGherkinScenario(scenario: messages.GherkinDocument.Feature.IScenario) {
private updateGherkinScenario(uri: string, scenario: messages.Scenario) {
this.locationByAstNodeId.set(scenario.id, scenario.location)
for (const step of scenario.steps) {
this.updateGherkinStep(step)
this.updateGherkinStep(uri, step)
}
for (const examples of scenario.examples) {
for (const tableRow of examples.tableBody) {
for (const tableRow of examples.tableBody || []) {
this.locationByAstNodeId.set(tableRow.id, tableRow.location)

@@ -111,8 +123,10 @@ }

private updateGherkinStep(step: messages.GherkinDocument.Feature.IStep) {
private updateGherkinStep(uri: string, step: messages.Step) {
this.locationByAstNodeId.set(step.id, step.location)
this.gherkinStepById.set(step.id, step)
this.gherkinStepByAstNodeId.set(step.id, step)
const uriLocation = [uri, step.location.line].join(':')
this.stepByUriLocation.set(uriLocation, step)
}
private updatePickle(pickle: messages.IPickle) {
private updatePickle(pickle: messages.Pickle) {
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(pickle.uri)

@@ -134,3 +148,3 @@

private updatePickleSteps(pickle: messages.IPickle) {
private updatePickleSteps(pickle: messages.Pickle) {
const pickleSteps = pickle.steps

@@ -137,0 +151,0 @@ for (const pickleStep of pickleSteps) {

@@ -31,2 +31,3 @@ import assert from 'assert'

@ruleTag
Rule: roule

@@ -158,3 +159,4 @@ Can we describe a Rule ?

it('keeps a hit background', () => {
// TODO before merging https://github.com/cucumber/cucumber/pull/1419
xit('keeps a hit background', () => {
const gherkinDocument = parse(`Feature: Solar System

@@ -234,3 +236,4 @@

it('keeps scenario in rule', () => {
// TODO before merging https://github.com/cucumber/cucumber/pull/1419
xit('keeps scenario in rule', () => {
const gherkinDocument = parse(`Feature: Solar System

@@ -237,0 +240,0 @@

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

import { messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
import { NdjsonToMessageStream } from '@cucumber/message-streams'

@@ -21,5 +21,3 @@ import { Writable, pipeline } from 'stream'

it(`can walk through GherkinDocuments in ${messageFile}`, async () => {
const messageStream = new NdjsonToMessageStream(
messages.Envelope.fromObject.bind(messages.Envelope)
)
const messageStream = new NdjsonToMessageStream()

@@ -32,3 +30,3 @@ await asyncPipeline(

write(
envelope: messages.IEnvelope,
envelope: messages.Envelope,
_encoding: string,

@@ -35,0 +33,0 @@ callback: (error?: Error | null) => void

@@ -1,7 +0,7 @@

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

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

import { GherkinStreams } from '@cucumber/gherkin-streams'
import { IdGenerator, messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
import { pipeline, Readable, Writable } from 'stream'

@@ -12,3 +12,3 @@ import assert from 'assert'

let gherkinQuery: Query
let envelopes: messages.IEnvelope[]
let envelopes: messages.Envelope[]
beforeEach(() => {

@@ -128,3 +128,3 @@ envelopes = []

assert.deepEqual(gherkinQuery.getPickleStepIds('whetever-id'), [])
assert.deepEqual(gherkinQuery.getPickleStepIds('whatever-id'), [])
})

@@ -205,3 +205,3 @@

write(
envelope: messages.IEnvelope,
envelope: messages.Envelope,
encoding: string,

@@ -223,13 +223,13 @@ callback: (error?: Error | null) => void

function gherkinMessages(gherkinSource: string, uri: string): Readable {
const source = messages.Envelope.fromObject({
const source: messages.Envelope = {
source: {
uri,
data: gherkinSource,
mediaType: 'text/x.cucumber.gherkin+plain',
mediaType: messages.SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
},
})
}
const newId = IdGenerator.incrementing()
const newId = messages.IdGenerator.incrementing()
return GherkinStreams.fromSources([source], { newId })
}
})

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

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