Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@cucumber/gherkin
Advanced tools
@cucumber/gherkin is an npm package that provides tools for parsing Gherkin language, which is used for writing structured tests in a human-readable format. It is part of the Cucumber suite of tools for Behavior-Driven Development (BDD). The package allows you to parse Gherkin documents, extract feature files, and convert them into a format that can be used for automated testing.
Parsing Gherkin Documents
This feature allows you to parse Gherkin documents from a stream. The code sample demonstrates how to create a readable stream from a Gherkin source string and parse it using GherkinStreams. The parsed data is then logged to the console.
const { GherkinStreams } = require('@cucumber/gherkin');
const { Readable } = require('stream');
const gherkinSource = `
Feature: Example feature
Scenario: Example scenario
Given a step
When another step
Then a final step
`;
const stream = Readable.from([gherkinSource]);
const parser = GherkinStreams.fromStream(stream);
parser.on('data', (envelope) => {
console.log(JSON.stringify(envelope, null, 2));
});
Extracting Feature Files
This feature allows you to extract and parse feature files from the file system. The code sample demonstrates how to create a readable stream from a feature file and parse it using GherkinStreams. The parsed data is then logged to the console.
const { GherkinStreams } = require('@cucumber/gherkin');
const fs = require('fs');
const filePath = 'path/to/your/feature/file.feature';
const stream = fs.createReadStream(filePath);
const parser = GherkinStreams.fromStream(stream);
parser.on('data', (envelope) => {
console.log(JSON.stringify(envelope, null, 2));
});
Converting Gherkin to JSON
This feature allows you to convert Gherkin documents into JSON format. The code sample demonstrates how to create a readable stream from a Gherkin source string, parse it using GherkinStreams, and log the Gherkin document in JSON format to the console.
const { GherkinStreams } = require('@cucumber/gherkin');
const { Readable } = require('stream');
const gherkinSource = `
Feature: Example feature
Scenario: Example scenario
Given a step
When another step
Then a final step
`;
const stream = Readable.from([gherkinSource]);
const parser = GherkinStreams.fromStream(stream);
parser.on('data', (envelope) => {
if (envelope.gherkinDocument) {
console.log(JSON.stringify(envelope.gherkinDocument, null, 2));
}
});
The 'cucumber' package is a comprehensive tool for running BDD tests written in Gherkin. It includes a test runner, step definitions, and reporting tools. While @cucumber/gherkin focuses on parsing Gherkin documents, 'cucumber' provides a full suite of tools for executing and managing BDD tests.
The 'jest-cucumber' package integrates Gherkin-based BDD testing with the Jest testing framework. It allows you to write feature files in Gherkin and implement step definitions using Jest. Compared to @cucumber/gherkin, 'jest-cucumber' is more focused on integrating with Jest for test execution.
The 'cypress-cucumber-preprocessor' package enables the use of Gherkin syntax in Cypress tests. It preprocesses feature files and allows you to write step definitions in JavaScript. This package is useful for those who want to combine the power of Cypress for end-to-end testing with Gherkin syntax for BDD.
Gherkin parser/compiler for JavaScript. Please see Gherkin for details.
[30.0.4] - 2024-11-15
FAQs
Gherkin parser
The npm package @cucumber/gherkin receives a total of 2,234,873 weekly downloads. As such, @cucumber/gherkin popularity was classified as popular.
We found that @cucumber/gherkin 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.