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

cucumber-generator

v2.0.1

Published

Generate step definitions for cucumber scenarios

Downloads

829

Readme

cucumber-generator

Build Status

Simple generator for cucumber features. It's still under development and currently can transform only simple features to following templates:

but basicaly there can be any yours template given as parameter. Of course you can use jest-cucumber templates but if you're using other library or you have many feature files and you don't want to copy-paste the code from console then this tool is made for you. :)

Generator will lookup for all features in given directory and generate .spec.ts files accordingly.

Installing

Do I need to state the obvious? :smile:

yarn add -D cucumber-generator

or

npm install -D cucumber-generator

CLI

API

Usage: npx cucumber-generator [parameters]

Options:
  --version                 Show version number                        [boolean]
  -h, --help                Show help                                  [boolean]
  --includeDirectory        If present, the file is generated into the directory
                            with same name as feature name (within output
                            folder)                   [boolean] [default: false]
  --output                                 [required] [choices: "stdio", "file"]
  -f, --featuresDirectory                                    [string] [required]
  --templatesDirectory                                                  [string]
  --template                                 [string] [default: "jest-cucumber"]
  --relativePathToFeatures                              [string] [default: "./"]
  --maintainStructure                                  [boolean] [default: true]
  --verbose                                           [boolean] [default: false]

Example

Consider this feature file

Feature: Car
  This feature describes how a car works
  Scenario: Unlock car
    Given keys
    Given locked car
    When person presses an unlock button
    And tries to open the door
    Then the door should open

  Scenario: Start engine
    Given unlocked car
    When person inserts key into ignition
    And turns the key
    Then car should start

after running npx cucumber-generator (with additional parameters described before) the result will be

import { defineFeature, loadFeature } from 'jest-cucumber';

const feature = loadFeature('../src/fixtures/Simple.feature');

defineFeature(feature, test => {
    test('Unlock car', ({ given, when, and, then }) => {
        given('keys', () => {
        });
        given('locked car', () => {
        });
        when('person presses an unlock button', () => {
        });
        and('tries to open the door', () => {
        });
        then('the door should open', () => {
        });
    });
    test('Start engine', ({ given, when, and, then }) => {
        given('unlocked car', () => {
        });
        when('person inserts key into ignition', () => {
        });
        and('turns the key', () => {
        });
        then('car should start', () => {
        });
    });
});

As module

API

There is TemplateGenerator class available with following constructor params:

  • template: string - mandatory parameter, defines a template to generate (currently just jest-cucumber)
  • options:
    • featuresDirectory: string - defines root for searching features
    • outputDirectory: string - defines where the files will be generated
    • maintainStructure: string | undefined - whether copy directory tree when generating spec files (default: true). If set to false, spec files will be generated all in single directory.
    • variables: Record<string, any> - variables passed to template file when generating
      • relativePathToFeatures: string - mandatory variable, defines where are feature files stored relatively to spec files (needed due to loadFeature function in jest-cucumber)

Examples

import {TemplateGenerator} from 'cucumber-generator';

const outputDirectory = './out';
const featuresDirectory = './src/test/features';
const relativePathToFeatures = '../src/test/features';

const generator = new TemplateGenerator('jest-cucumber', {
    outputDirectory,
    featuresDirectory,
    variables: {
      relativePathToFeatures,
    },
});
const result = await generator.generate();

Contribution

Any help with the package is always welcome, just be sure to write and run the tests.