Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
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));
Cucumber is a tool for running automated tests written in plain language. It supports the Gherkin syntax and integrates with various programming languages. Compared to gherkin, Cucumber provides a full-fledged testing framework, including test execution and reporting.
Gherkin parser/compiler for JavaScript. Please see Gherkin for details.
const gherkin = require('gherkin')
const options = {
includeSource: true,
includeGherkinDocument: true,
includePickles: true,
}
const stream = gherkin.fromPaths(['features/hello.feature'])
// Pipe the stream to another stream that can read messages.
stream.pipe(...)
FAQs
Gherkin parser
The npm package gherkin receives a total of 864,498 weekly downloads. As such, gherkin popularity was classified as popular.
We found that gherkin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.