Socket
Socket
Sign inDemoInstall

gherkin

Package Overview
Dependencies
Maintainers
4
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gherkin

Gherkin parser


Version published
Weekly downloads
903K
decreased by-4.68%
Maintainers
4
Weekly downloads
 
Created

What is gherkin?

The gherkin npm package is a parser for the Gherkin language, which is used to write structured tests in a business-readable, domain-specific language. It is commonly used in Behavior-Driven Development (BDD) frameworks like Cucumber.

What are gherkin's main functionalities?

Parsing Gherkin Syntax

This feature allows you to parse Gherkin syntax into a structured format. The code sample demonstrates how to parse a simple Gherkin feature file and output the resulting JSON structure.

const { Parser } = require('gherkin');
const parser = new Parser();
const gherkinDocument = parser.parse(`
Feature: Example feature
  Scenario: Example scenario
    Given a precondition
    When an action is performed
    Then an outcome is expected
`);
console.log(JSON.stringify(gherkinDocument, null, 2));

Tokenizing Gherkin Syntax

This feature allows you to tokenize Gherkin syntax, breaking it down into individual tokens. The code sample demonstrates how to read and print tokens from a Gherkin feature file.

const { TokenScanner, TokenMatcher, GherkinLine, Token } = require('gherkin');
const scanner = new TokenScanner(`
Feature: Example feature
  Scenario: Example scenario
    Given a precondition
    When an action is performed
    Then an outcome is expected
`);
const matcher = new TokenMatcher();
let token;
while ((token = scanner.read()) && token.isEOF === false) {
  console.log(token);
}

Generating Pickles

This feature allows you to generate 'pickles' from Gherkin documents. Pickles are a simplified, executable representation of Gherkin scenarios. The code sample demonstrates how to parse a Gherkin document and compile it into pickles.

const { Parser, Compiler } = require('gherkin');
const parser = new Parser();
const compiler = new Compiler();
const gherkinDocument = parser.parse(`
Feature: Example feature
  Scenario: Example scenario
    Given a precondition
    When an action is performed
    Then an outcome is expected
`);
const pickles = compiler.compile(gherkinDocument);
console.log(JSON.stringify(pickles, null, 2));

Other packages similar to gherkin

Keywords

FAQs

Package last updated on 23 Sep 2018

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