1.3.1 • Published 4 years ago

auto-jest-cucumber v1.3.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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');
    }
  ]
];
1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago