@cucumber/gherkin-utils
Advanced tools
Comparing version 8.0.2 to 8.0.3
{ | ||
"name": "@cucumber/gherkin-utils", | ||
"version": "8.0.2", | ||
"version": "8.0.3", | ||
"description": "Various Gherkin utilities", | ||
@@ -34,31 +34,31 @@ "main": "dist/src/index.js", | ||
"@cucumber/message-streams": "^4.0.1", | ||
"@types/mocha": "10.0.0", | ||
"@types/node": "18.11.9", | ||
"@typescript-eslint/eslint-plugin": "5.43.0", | ||
"@typescript-eslint/parser": "5.43.0", | ||
"ajv": "8.11.2", | ||
"@types/mocha": "10.0.1", | ||
"@types/node": "18.16.7", | ||
"@typescript-eslint/eslint-plugin": "5.59.5", | ||
"@typescript-eslint/parser": "5.59.5", | ||
"ajv": "8.12.0", | ||
"ajv-cli": "5.0.0", | ||
"eslint": "8.28.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint": "8.40.0", | ||
"eslint-config-prettier": "8.8.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"eslint-plugin-react": "7.31.11", | ||
"eslint-plugin-react": "7.32.2", | ||
"eslint-plugin-react-hooks": "4.6.0", | ||
"eslint-plugin-simple-import-sort": "8.0.0", | ||
"eslint-plugin-simple-import-sort": "10.0.0", | ||
"fast-glob": "3.2.12", | ||
"mocha": "10.1.0", | ||
"npm-check-updates": "16.4.1", | ||
"prettier": "2.7.1", | ||
"mocha": "10.2.0", | ||
"npm-check-updates": "16.10.12", | ||
"prettier": "2.8.8", | ||
"pretty-quick": "3.1.3", | ||
"rimraf": "^3.0.2", | ||
"rimraf": "^4.0.0", | ||
"ts-node": "10.9.1", | ||
"tsconfig-paths": "4.1.0", | ||
"typescript": "4.9.3" | ||
"tsconfig-paths": "4.2.0", | ||
"typescript": "5.0.4" | ||
}, | ||
"dependencies": { | ||
"@cucumber/gherkin": "^25.0.0", | ||
"@cucumber/messages": "^19.1.4", | ||
"@teppeis/multimaps": "2.0.0", | ||
"commander": "9.4.1", | ||
"@cucumber/gherkin": "^26.0.0", | ||
"@cucumber/messages": "^21.0.0", | ||
"@teppeis/multimaps": "3.0.0", | ||
"commander": "10.0.1", | ||
"source-map-support": "^0.5.21" | ||
@@ -65,0 +65,0 @@ }, |
@@ -8,2 +8,5 @@ "use strict"; | ||
return (0, walkGherkinDocument_1.walkGherkinDocument)(gherkinDocument, '', { | ||
comment(comment, content) { | ||
return content.concat(comment.text).concat('\n'); | ||
}, | ||
feature(feature, content) { | ||
@@ -10,0 +13,0 @@ return content |
@@ -13,5 +13,7 @@ "use strict"; | ||
function walkGherkinDocument(gherkinDocument, initialValue, handlers) { | ||
const commentsStack = gherkinDocument.comments.slice(); | ||
let acc = initialValue; | ||
const h = Object.assign(Object.assign({}, makeDefaultHandlers()), handlers); | ||
const feature = gherkinDocument.feature; | ||
acc = walkComments(popCommentsUntil(feature === null || feature === void 0 ? void 0 : feature.location), acc); | ||
if (!feature) | ||
@@ -30,2 +32,3 @@ return acc; | ||
acc = walkTags(child.rule.tags || [], acc); | ||
acc = walkComments(popCommentsUntil(child.rule.location), acc); | ||
acc = h.rule(child.rule, acc); | ||
@@ -43,2 +46,5 @@ for (const ruleChild of child.rule.children) { | ||
return acc; | ||
function walkComments(comments, acc) { | ||
return comments.reduce((acc, comment) => h.comment(comment, acc), acc); | ||
} | ||
function walkTags(tags, acc) { | ||
@@ -51,2 +57,3 @@ return tags.reduce((acc, tag) => h.tag(tag, acc), acc); | ||
function walkStep(step, acc) { | ||
acc = walkComments(popCommentsUntil(step.location), acc); | ||
acc = h.step(step, acc); | ||
@@ -70,2 +77,3 @@ if (step.docString) { | ||
function walkStepContainer(stepContainer, acc) { | ||
acc = walkComments(popCommentsUntil(stepContainer.location), acc); | ||
const scenario = 'tags' in stepContainer ? stepContainer : null; | ||
@@ -79,2 +87,3 @@ acc = walkTags((scenario === null || scenario === void 0 ? void 0 : scenario.tags) || [], acc); | ||
for (const examples of scenario.examples || []) { | ||
acc = walkComments(popCommentsUntil(examples.location), acc); | ||
acc = walkTags(examples.tags || [], acc); | ||
@@ -90,2 +99,14 @@ acc = h.examples(examples, acc); | ||
} | ||
function popCommentsUntil(location) { | ||
let count = 0; | ||
for (const comment of commentsStack) { | ||
if (location === undefined || comment.location.line < location.line) { | ||
count++; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return commentsStack.splice(0, count); | ||
} | ||
} | ||
@@ -92,0 +113,0 @@ exports.walkGherkinDocument = walkGherkinDocument; |
@@ -166,8 +166,12 @@ "use strict"; | ||
}); | ||
xit('renders comments', () => { | ||
it('renders comments', () => { | ||
checkGherkinToAstToGherkin(`# one | ||
# two | ||
Feature: hello | ||
# three | ||
# four | ||
Scenario: one | ||
# two | ||
# five | ||
# six | ||
Given a doc string: | ||
@@ -181,2 +185,22 @@ """ | ||
}); | ||
it('renders just comments', () => { | ||
checkGherkinToAstToGherkin(`# one | ||
# two | ||
`); | ||
}); | ||
it('renders block comments', () => { | ||
checkGherkinToAstToGherkin(`Feature: block comments | ||
Background: Archimedes | ||
Given a lever long enough | ||
And a fulcrum on which to place it | ||
# Scenario: move the world | ||
# When I apply force to the lever | ||
# Then I shall move the world | ||
Scenario: nice cup of tea | ||
When I brew some tea | ||
Then I should have a cozy time | ||
`); | ||
}); | ||
it('renders descriptions when set', () => { | ||
@@ -200,3 +224,3 @@ checkGherkinToAstToGherkin(`Feature: hello | ||
}); | ||
const featureFiles = fast_glob_1.default.sync(`${__dirname}/../../../gherkin/testdata/good/*.feature`); | ||
const featureFiles = fast_glob_1.default.sync(`${__dirname}/../../testdata/good/*.feature`); | ||
for (const featureFile of featureFiles) { | ||
@@ -203,0 +227,0 @@ const relativePath = path_1.default.relative(__dirname, featureFile); |
@@ -12,8 +12,12 @@ "use strict"; | ||
const gherkinDocument = (0, parse_1.default)(` | ||
#1 | ||
@A | ||
Feature: B | ||
#2 | ||
Background: C | ||
#3 | ||
@D | ||
Scenario: E | ||
#4 | ||
Given F | ||
@@ -24,2 +28,3 @@ | ||
#5 | ||
Rule: I | ||
@@ -32,2 +37,3 @@ @J | ||
#6 | ||
Examples: Q | ||
@@ -46,3 +52,3 @@ | ||
const handlers = { | ||
comment: (comment, acc) => acc, | ||
comment: (comment, acc) => acc.concat(comment.text.trim()), | ||
dataTable: (dataTable, acc) => acc, | ||
@@ -61,5 +67,5 @@ docString: (docString, acc) => acc.concat(docString.content), | ||
const names = (0, src_1.walkGherkinDocument)(gherkinDocument, [], handlers); | ||
assert_1.default.deepEqual(names, 'A B C D E F G H I J K L M N O P Q R S T U V W'.split(' ')); | ||
assert_1.default.deepEqual(names, '#1 A B #2 C #3 D E #4 F G H #5 I J K L M N O P #6 Q R S T U V W'.split(' ')); | ||
}); | ||
}); | ||
//# sourceMappingURL=walkGherkinDocumentTest.js.map |
{ | ||
"name": "@cucumber/gherkin-utils", | ||
"version": "8.0.2", | ||
"version": "8.0.3", | ||
"description": "Various Gherkin utilities", | ||
@@ -34,31 +34,31 @@ "main": "dist/src/index.js", | ||
"@cucumber/message-streams": "^4.0.1", | ||
"@types/mocha": "10.0.0", | ||
"@types/node": "18.11.9", | ||
"@typescript-eslint/eslint-plugin": "5.43.0", | ||
"@typescript-eslint/parser": "5.43.0", | ||
"ajv": "8.11.2", | ||
"@types/mocha": "10.0.1", | ||
"@types/node": "18.16.7", | ||
"@typescript-eslint/eslint-plugin": "5.59.5", | ||
"@typescript-eslint/parser": "5.59.5", | ||
"ajv": "8.12.0", | ||
"ajv-cli": "5.0.0", | ||
"eslint": "8.28.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint": "8.40.0", | ||
"eslint-config-prettier": "8.8.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"eslint-plugin-react": "7.31.11", | ||
"eslint-plugin-react": "7.32.2", | ||
"eslint-plugin-react-hooks": "4.6.0", | ||
"eslint-plugin-simple-import-sort": "8.0.0", | ||
"eslint-plugin-simple-import-sort": "10.0.0", | ||
"fast-glob": "3.2.12", | ||
"mocha": "10.1.0", | ||
"npm-check-updates": "16.4.1", | ||
"prettier": "2.7.1", | ||
"mocha": "10.2.0", | ||
"npm-check-updates": "16.10.12", | ||
"prettier": "2.8.8", | ||
"pretty-quick": "3.1.3", | ||
"rimraf": "^3.0.2", | ||
"rimraf": "^4.0.0", | ||
"ts-node": "10.9.1", | ||
"tsconfig-paths": "4.1.0", | ||
"typescript": "4.9.3" | ||
"tsconfig-paths": "4.2.0", | ||
"typescript": "5.0.4" | ||
}, | ||
"dependencies": { | ||
"@cucumber/gherkin": "^25.0.0", | ||
"@cucumber/messages": "^19.1.4", | ||
"@teppeis/multimaps": "2.0.0", | ||
"commander": "9.4.1", | ||
"@cucumber/gherkin": "^26.0.0", | ||
"@cucumber/messages": "^21.0.0", | ||
"@teppeis/multimaps": "3.0.0", | ||
"commander": "10.0.1", | ||
"source-map-support": "^0.5.21" | ||
@@ -65,0 +65,0 @@ }, |
@@ -12,2 +12,5 @@ import * as messages from '@cucumber/messages' | ||
return walkGherkinDocument<string>(gherkinDocument, '', { | ||
comment(comment, content) { | ||
return content.concat(comment.text).concat('\n') | ||
}, | ||
feature(feature, content) { | ||
@@ -14,0 +17,0 @@ return content |
@@ -17,5 +17,7 @@ import * as messages from '@cucumber/messages' | ||
): Acc { | ||
const commentsStack = gherkinDocument.comments.slice() | ||
let acc = initialValue | ||
const h: GherkinDocumentHandlers<Acc> = { ...makeDefaultHandlers<Acc>(), ...handlers } | ||
const feature = gherkinDocument.feature | ||
acc = walkComments(popCommentsUntil(feature?.location), acc) | ||
if (!feature) return acc | ||
@@ -32,2 +34,3 @@ acc = walkTags(feature.tags || [], acc) | ||
acc = walkTags(child.rule.tags || [], acc) | ||
acc = walkComments(popCommentsUntil(child.rule.location), acc) | ||
acc = h.rule(child.rule, acc) | ||
@@ -45,2 +48,6 @@ for (const ruleChild of child.rule.children) { | ||
function walkComments(comments: readonly messages.Comment[], acc: Acc): Acc { | ||
return comments.reduce((acc, comment) => h.comment(comment, acc), acc) | ||
} | ||
function walkTags(tags: readonly messages.Tag[], acc: Acc): Acc { | ||
@@ -55,2 +62,3 @@ return tags.reduce((acc, tag) => h.tag(tag, acc), acc) | ||
function walkStep(step: messages.Step, acc: Acc): Acc { | ||
acc = walkComments(popCommentsUntil(step.location), acc) | ||
acc = h.step(step, acc) | ||
@@ -80,2 +88,3 @@ if (step.docString) { | ||
): Acc { | ||
acc = walkComments(popCommentsUntil(stepContainer.location), acc) | ||
const scenario: messages.Scenario = 'tags' in stepContainer ? stepContainer : null | ||
@@ -90,2 +99,3 @@ acc = walkTags(scenario?.tags || [], acc) | ||
for (const examples of scenario.examples || []) { | ||
acc = walkComments(popCommentsUntil(examples.location), acc) | ||
acc = walkTags(examples.tags || [], acc) | ||
@@ -101,4 +111,17 @@ acc = h.examples(examples, acc) | ||
} | ||
function popCommentsUntil(location?: messages.Location): readonly messages.Comment[] { | ||
let count = 0 | ||
for (const comment of commentsStack) { | ||
if (location === undefined || comment.location.line < location.line) { | ||
count++ | ||
} else { | ||
break | ||
} | ||
} | ||
return commentsStack.splice(0, count) | ||
} | ||
} | ||
function makeDefaultHandlers<Acc>() { | ||
@@ -105,0 +128,0 @@ const defaultHandlers: GherkinDocumentHandlers<Acc> = { |
@@ -152,8 +152,12 @@ import assert from 'assert' | ||
xit('renders comments', () => { | ||
it('renders comments', () => { | ||
checkGherkinToAstToGherkin(`# one | ||
# two | ||
Feature: hello | ||
# three | ||
# four | ||
Scenario: one | ||
# two | ||
# five | ||
# six | ||
Given a doc string: | ||
@@ -168,2 +172,24 @@ """ | ||
it('renders just comments', () => { | ||
checkGherkinToAstToGherkin(`# one | ||
# two | ||
`) | ||
}) | ||
it('renders block comments', () => { | ||
checkGherkinToAstToGherkin(`Feature: block comments | ||
Background: Archimedes | ||
Given a lever long enough | ||
And a fulcrum on which to place it | ||
# Scenario: move the world | ||
# When I apply force to the lever | ||
# Then I shall move the world | ||
Scenario: nice cup of tea | ||
When I brew some tea | ||
Then I should have a cozy time | ||
`) | ||
}) | ||
it('renders descriptions when set', () => { | ||
@@ -188,3 +214,3 @@ checkGherkinToAstToGherkin(`Feature: hello | ||
const featureFiles = fg.sync(`${__dirname}/../../../gherkin/testdata/good/*.feature`) | ||
const featureFiles = fg.sync(`${__dirname}/../../testdata/good/*.feature`) | ||
for (const featureFile of featureFiles) { | ||
@@ -191,0 +217,0 @@ const relativePath = path.relative(__dirname, featureFile) |
@@ -8,8 +8,12 @@ import assert from 'assert' | ||
const gherkinDocument = parse(` | ||
#1 | ||
@A | ||
Feature: B | ||
#2 | ||
Background: C | ||
#3 | ||
@D | ||
Scenario: E | ||
#4 | ||
Given F | ||
@@ -20,2 +24,3 @@ | ||
#5 | ||
Rule: I | ||
@@ -28,2 +33,3 @@ @J | ||
#6 | ||
Examples: Q | ||
@@ -43,3 +49,3 @@ | ||
const handlers: GherkinDocumentHandlers<string[]> = { | ||
comment: (comment, acc) => acc, | ||
comment: (comment, acc) => acc.concat(comment.text.trim()), | ||
dataTable: (dataTable, acc) => acc, | ||
@@ -59,4 +65,4 @@ docString: (docString, acc) => acc.concat(docString.content), | ||
const names = walkGherkinDocument<string[]>(gherkinDocument, [], handlers) | ||
assert.deepEqual(names, 'A B C D E F G H I J K L M N O P Q R S T U V W'.split(' ')) | ||
assert.deepEqual(names, '#1 A B #2 C #3 D E #4 F G H #5 I J K L M N O P #6 Q R S T U V W'.split(' ')) | ||
}) | ||
}) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
343085
4301
86
+ Added@cucumber/gherkin@26.2.0(transitive)
+ Added@cucumber/messages@21.0.1(transitive)
+ Added@teppeis/multimaps@3.0.0(transitive)
+ Addedcommander@10.0.1(transitive)
- Removed@cucumber/gherkin@25.0.2(transitive)
- Removed@cucumber/messages@19.1.4(transitive)
- Removed@teppeis/multimaps@2.0.0(transitive)
- Removedcommander@9.4.1(transitive)
Updated@cucumber/gherkin@^26.0.0
Updated@cucumber/messages@^21.0.0
Updated@teppeis/multimaps@3.0.0
Updatedcommander@10.0.1