question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cucumber-js doesn't find step definitions

See original GitHub issue

Hi, I’m a newbie who’s been trying for hours to get cucumber-js to find my step definitions. I’ve come up with this simple example.

In features/foo.feature:

Feature: Foo
  Scenario: Bar
    Given FooBar

In features/step_definitions/step_defs.js:

var {defineSupportCode} = require('cucumber');

defineSupportCode(function({Given}) {
    Given('FooBar', function () {
      return 'pending';
    });    
});

I get this result:

Feature: Foo

  Scenario: Bar
  ? Given FooBar

Warnings:

1) Scenario: Bar - features\foo.feature:2
   Step: Given FooBar - features\foo.feature:3
   Message:
     Undefined. Implement with the following snippet:

       Given('FooBar', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

1 scenario (1 undefined)
1 step (1 undefined)
0m00.000s

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:48 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
charlierudolphcommented, Feb 4, 2017

Alright. I believe I figured this out.

When using a global install of cucumber to run the feature tests, you are still defining support code by requiring the local install of cucumber. The fact that these are two different instances results in no step definitions being loaded.

Is there any reason you can’t use the local install for running the command? I do this on mac by adding “./node_modules/.bin” to my path.

I don’t like the idea of trying to making this work by having the global install try to require the local install in order to get the step definitions. I also dislike the global install since it makes you have to specify things like compile modules by their absolute path.

If this is possible on windows, I’d prefer to just update the documentation to mention that this cannot be used as a global install.

2reactions
GeeChaocommented, Jun 15, 2017

@vvedachalam

It works for me.

The only thing I did was move step_definitions to under the features directory

also i did a npm install cucumber@1.3.3 --save-dev

then ran node_modules/cucumber/bin/cucumber.js features/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cucumber not seeing steps in javascript project - Stack Overflow
I believe you need to have features and step_definitions folders in the same directory for cucumber to find step definitions.
Read more >
can't run cucumber is step definitions are located in non ...
WebStorm 2019.2 (now available as an Early Access Preview) can detect Cucumber.js step definitions located in folders other than the step_definitions folder.
Read more >
Was unable to find a step for “”: Mapping stepDefinitions to ...
While working with cucumber, when steps are not mapped completely with the feature files, it usually gives this as a warning.
Read more >
FAQ - Cucumber Documentation
If Cucumber is telling you that your steps are undefined, when you have defined step definitions, this means that Cucumber cannot find your...
Read more >
cucumber/cucumber-js - Gitter
In fact, the 'before' hook code does not seem to get executed at all for the second ... I have a question regarding...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found