Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@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.
[15.2.0] - 2022-05-24
ParameterInfo
(#124)FAQs
Cucumber Expressions - a simpler alternative to Regular Expressions
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
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.