npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cucumon

v1.4.2

Published

Cucumber Gherkin Feature file parser with custom additional features

Downloads

198

Readme

Cucumon

Gherkin like feature file parser with a dash of lemon.

How to use

$ npm install cucumon
const Cucumon = require("cucumon");

const options = {
    tagExpression : "", //@focus
    //clubBgSteps : true,
}
const cucumonSlice = new Cucumon(options);
const output = cucumonSlice.parse(featureFileAsString);

Documentation

Feature file format

Cucumon supports gherkin feature file format.

@tag @tag2
@tag3
Feature: statement

Description

Rule: some rule

    Background: statement
        Given some step
    
    Scenario: statment
        When some step

    Scenario Outline: statement <header>
        Then some step
        And data table
        #> {}
        |header|<header>|
        But doc string
        #> json
        """
        { header: "<header>" }
        """

        Examples:
        |header|
        |val|

Rule: Other sub feature

    Background: statement
        Given some step
    
    Example: statment
        When some step

    @taghere
    Scenario Template: statement <header>
        Then some step

        Scenarios:
        |header|
        |val|

Note the instruction statment #> {}. Instruction statments are special comments which can help parser to take some extra steps. Currently, they are supported with scenario, steps, docstring, and data table inputs.

Result format

{
    feature: {
        "keyword": "Feature",
        "description": "",
        "statement": "Special Characters",
        "lineNumber": 1,
        "tags": [],
        rules: [
            {
                "keyword": "Rule",
                "description": "",
                "statement": "some rule",
                "lineNumber": 2,
                "hasBgSection": true,
                "background": {
                    "keyword": "Background",
                    "statement": "one per rule",
                    "description": "Background can have description",
                    "lineNumber": 14,
                    "id": -1,
                    "steps": [
                        {
                            "keyword": "Given",
                            "statement": "a string tokenizer",
                            "lineNumber": 17,
                            "arg": null
                        }
                    ]
                },
                scenarios: [
                    {
                        "keyword": "Scenario",
                        "statement": "normal scenario",
                        "description": "",
                        "lineNumber": 3,
                        "id": 1,
                        "tags": [],
                        "steps": [
                            {
                                "keyword": "Given",
                                "statement": "an example",
                                "lineNumber": 4,
                                "arg": {
                                    "content": "some docstring",
                                    "type": "DocString",
                                    "lineNumber": 26,
                                    "instruction": "no format; single line;"
                                }
                            }
                        ]
                    },{
                        "keyword": "Scenario Template",
                        "statement": "scenario outline",
                        "description": "",
                        "lineNumber": 3,
                        "id": 1,
                        "tags": ["@wip"],
                        "expanded" : [
                            {
                                "keyword": "Scenario Template",
                                "statement": "scenario outline",
                                "description": "",
                                "lineNumber": 3,
                                "id": 1,
                                "steps": [
                                    {
                                        "keyword": "Given",
                                        "statement": "an example",
                                        "lineNumber": 4,
                                        "arg": null
                                    }
                                ],
                                "tags": [ "@wip", "@examples" ],
                                "examplesLineNumber": [ 19 ]
                            }
                        ],
                        "examples": [
                            {
                                "lineNumber": 10,
                                "rows": [
                                    {
                                        "lineNumber": 11,
                                        "regex": [ {} ],
                                        "cells": [ "data" ]
                                    }, {
                                        "lineNumber": 19,
                                        "cells": [ "" ]
                                    }
                                ],
                                "instruction": "instruction",
                                "tags": [ "@examples" ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

Options

new Cucumon({clubBgSteps: false});

You can set clubBgSteps: true to club background steps with scenario steps.

Check sample parsed response for better idea;

Additional Features

  • Cucumon supports multiple examples
  • You can use your own logic to generate scenarios for scenario outline
Feature: Matrix Outliner

    Scenario Template: Matrix example
        Given an example 
        And I can Multiply <a> with <b>

        #> matrix: row 1
        Examples:
        | a |
        | 3 |

        #> matrix: row 2
        Examples:
        | b |
        | 4 |

Note that #> is a special statment considered as instruction statement. You'll get it's value as outline.examples[0].instruction.

const cucumon = new Cucumon({clubBgSteps: false});
cucumon.registerOutlineExpander((outline) => {});

Other

  • Check bexp to evaluate tag expression.