
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
@cucumber/cucumber-expressions
Advanced tools
Cucumber Expressions - a simpler alternative to Regular Expressions
@cucumber/cucumber-expressions is a package that allows you to define and match text patterns in a way that is useful for writing and running Cucumber tests. It provides a way to define patterns that can be used to match steps in Gherkin scenarios, making it easier to write readable and maintainable test cases.
Defining Cucumber Expressions
This feature allows you to define Cucumber expressions that can be used to match text patterns in Gherkin steps. In this example, the expression 'I have {int} cukes' is defined and matched against the text 'I have 42 cukes', extracting the integer value 42.
const { CucumberExpression, ParameterTypeRegistry } = require('@cucumber/cucumber-expressions');
const parameterTypeRegistry = new ParameterTypeRegistry();
const expression = new CucumberExpression('I have {int} cukes', parameterTypeRegistry);
const value = expression.match('I have 42 cukes')[0].getValue();
console.log(value); // 42
Custom Parameter Types
This feature allows you to define custom parameter types that can be used in Cucumber expressions. In this example, a custom parameter type 'word' is defined to match any word, and it is used in the expression 'I have a {word}', extracting the word 'cucumber'.
const { ParameterType, ParameterTypeRegistry, CucumberExpression } = require('@cucumber/cucumber-expressions');
const parameterTypeRegistry = new ParameterTypeRegistry();
parameterTypeRegistry.defineParameterType(new ParameterType('word', /\w+/, String, s => s));
const expression = new CucumberExpression('I have a {word}', parameterTypeRegistry);
const value = expression.match('I have a cucumber')[0].getValue();
console.log(value); // 'cucumber'
Regular Expressions
This feature allows you to use regular expressions to match text patterns in Gherkin steps. In this example, the regular expression /I have (\d+) cukes/ is used to match the text 'I have 42 cukes', extracting the integer value 42.
const { RegularExpression, ParameterTypeRegistry } = require('@cucumber/cucumber-expressions');
const parameterTypeRegistry = new ParameterTypeRegistry();
const expression = new RegularExpression(/I have (\d+) cukes/, parameterTypeRegistry);
const value = expression.match('I have 42 cukes')[0].getValue();
console.log(value); // 42
The 'cucumber' package is the main package for running Cucumber tests in JavaScript. It includes support for defining and running Gherkin scenarios, but it does not provide the same level of flexibility for defining custom expressions and parameter types as @cucumber/cucumber-expressions.
The 'gherkin' package is responsible for parsing Gherkin syntax, which is used to define Cucumber scenarios. While it focuses on parsing the Gherkin language, it does not provide the same capabilities for defining and matching custom expressions as @cucumber/cucumber-expressions.
The 'jest-cucumber' package allows you to write Cucumber-style tests using the Jest testing framework. It provides a way to define Gherkin scenarios and match them to step definitions, but it does not offer the same level of customization for expressions and parameter types as @cucumber/cucumber-expressions.
[18.0.1] - 2024-10-28
FAQs
Cucumber Expressions - a simpler alternative to Regular Expressions
The npm package @cucumber/cucumber-expressions receives a total of 922,878 weekly downloads. As such, @cucumber/cucumber-expressions popularity was classified as popular.
We found that @cucumber/cucumber-expressions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.