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

auto-jest-cucumber

v1.3.1

Published

Library for automatic setup of jest-cucumber tests based on .feature files and JavaScript step definitions.

Downloads

6

Readme

Auto Jest Cucumber

Library for automatic setup of jest-cucumber tests based on .feature files and JavaScript step definitions.

Overview

Auto Jest Cucumber utilizes jest-cucumber to link step definitions to .feature files, making it easy to reutilize step definitions and facilitating the state management for each Scenario/Scenario Outline.

Motivation

Even though jest-cucumber is very useful for linking tests running on Jest to Cucumber .feature files, the steps definition in pure jest-cucumber can be a little awkward. You have to basically remake the .feature file in JavaScript, defining every Scenario with all its steps. This is sub-optimal, as this information is already available in the .feature file and it gets hard to reuse steps in different Scenarios and .feature files. One workaround for that is to store the step definitions somewhere and import them when we configure jest-cucumber, but then this configuration would be a (completely pointless) second .feature file written in JavaScript. Auto Jest Cucumber can do this configuration automatically, parsing the .feature file, importing steps automatically from the steps definitions (in a similar manner to how Cucumber does it) and setting up the tests on Jest using jest-cucumber.

Getting Started

The following steps show how to setup a basic feature test using Auto Jest Cucumber with the default options.

It is possible to customize this behaviour, however that is not addressed here and is undocumented for now. You can check the file src/features/self.js for an example.

Install Auto Jest Cucumber:

npm install auto-jest-cucumber --save-dev

Add the following to your Jest configuration:

  "testPathIgnorePatterns": [
    "<rootDir>(.*)/node_modules/(?!auto-jest-cucumber).*"
  ],
  "moduleFileExtensions": [
    "js",
    "feature"
  ],
  "haste": {
    "providesModuleNodeModules": ["auto-jest-cucumber"]
  }

Add a feature file inside the features folder:

# features/rocket-launching.feature

Feature: Rocket Launching

Scenario: Launching a SpaceX rocket
  Given I am Elon Musk attempting to launch rocket "Falcon 9" into space
  When I launch the rocket
  Then the rocket should end up in space
  And the booster(s) should land back on the launch pad
  And nobody should doubt me ever again

Add a steps definition file inside the features folder:

// features/rocket-launching.steps.js

var Rocket = require('../rocket');

module.exports = [
  [
    /^I am Elon Musk attempting to launch rocket (.*) into space$/,
    function (name) {
      this.rocket = new Rocket(name);
    }
  ],
  [
    'I launch the rocket',
    function () {
      this.rocket.launch();
    }
  ],
  [
    'the rocket should end up in space',
    function () {
      expect(this.rocket.isInSpace).toBe(true);
    }
  ],
  [
    'the booster(s) should land back on the launch pad',
    function () {
      expect(this.rocket.boostersLanded).toBe(true);
    }
  ],
  [
    'nobody should doubt me ever again',
    function () {
      expect('people').not.toBe('haters');
    }
  ]
];