3

Other versions of cucumber, it is possible to dump a list of all steps. However this is not supported in javascript. For example:

cucumber -f usage --dry-run

If you can get access to the World object or Cucumber, I think there might be a way to list all of the regexps / functions that Cucumber uses to parse the .feature files. Does anyone know the inner workings of the javascript version that could point me in the right direction?

orde
  • 5,233
  • 6
  • 31
  • 33
bryce
  • 763
  • 6
  • 13

3 Answers3

2

I found it was easier to write my own, this will require all of the steps an outputs them as they are found.

var container = {
    myFn: function(type, regExp, fn) {
      console.log(type +' '+regExp.toString());
    },

    Given: function(regExp, fn) {
      this.myFn('Given', regExp, fn);
    },
    Then : function(regExp, fn) {
      this.myFn('Then', regExp, fn);
    },
    When : function(regExp, fn) {
      this.myFn('When', regExp, fn);
    }
  };

var steps = require('./stepDefinitions');
steps.apply(container);


// stepDefinitions
module.exports = function() {

  this.Given(/^I run Cucumber with Protractor$/, function(next) {
    next();
  });
};
bryce
  • 763
  • 6
  • 13
0

This is what we use for checking which steps definitions are being used:

cucumber-js --require step-definitions/**/*.ts --tags \"@automated and not @skip\" --format usage

We don't run all our tests on every push, but we do run this check, because it helps to make sure that feature files or steps definitions didn't break because of a regex problem.

logan
  • 3,416
  • 1
  • 33
  • 45
0

A quick command line solution to list all defined steps:

sed -e '/^[Given|When|Then]/!d' **/*.steps.js | sort | sed 's/, async function (.*{/)/g'

Breaking it down:

  • sed -e '/^[Given|When|Then]/!d' **/*.steps.js finds all lines that start with "Given", "When" or "Then" in all files that are named *.steps.js.
  • sort sorts the output.
  • sed 's/, async function (.*{/)/g' cleans up each line by replacing ", async function(...) {" with ")"

Optional: Add as an npm/yarn command

You can add it as a script in your package.json, e.g.:

  "scripts": {
    ...
    "cucumber:list": "sed -e '/^[Given|When|Then]/!d' **/*.steps.js | sort | sed 's/, async function (.*{/)/g'",
    ...
  },

And then call yarn cucumber:list.

Paddy Mann
  • 1,169
  • 12
  • 18