Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cucumber/gherkin

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cucumber/gherkin

Gherkin parser

  • 24.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6M
decreased by-39.03%
Maintainers
2
Weekly downloads
 
Created

What is @cucumber/gherkin?

@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.

What are @cucumber/gherkin's main functionalities?

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));
  }
});

Other packages similar to @cucumber/gherkin

Keywords

FAQs

Package last updated on 31 May 2022

Did you know?

Socket

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.

Install

Related posts

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