timjroberts / cucumber-js-tsflow

Provides 'specflow' like bindings for Cucumber.js in TypeScript 1.7+.
MIT License
133 stars 34 forks source link

Undefined. Implement with the following snippet Error with Cucumber 3.0.1 #28

Closed ra9r closed 5 years ago

ra9r commented 7 years ago

When running CucumberJS v3.0.1 on the command line without any parameters; and given the following project assets/directories ...

KaraokeProject
 |
 +- package.json
 +- node_modules
 +- features
    |
    +- step_definitions
    |   |
    |   +- actionwords.js
    |   +- step_definitions.js
    |
    +- karaoke.feature

karakoke.feature

Feature: Sing Karaoke
    Verify that I can turn on the karaoke machine and sing.

  Scenario: Singer sings the lyrics to song
    Given I select the song "Unchain My Heart"
    And I see the lyrics
    Then I can sing the song

step_definitions.js

module.exports = function () {
    this.Before(function (scenario) {
        this.actionwords = Object.create(require('./actionwords.js').Actionwords);
    });

    this.After(function (scenario) {
        this.actionwords = null;
    });

    this.Given('I select the song {string}', function (song_name, callback) {
        this.actionwords.iSelectTheSongSongName(song_name);
        callback();
    });

    this.Given('I see the lyrics', function (callback) {
        this.actionwords.iSeeTheLyrics();
        callback();
    });

    this.Then('I can sing the song', function (callback) {
        this.actionwords.iCanSingTheSong();
        callback();
    });
}

actionwords.js

exports.Actionwords = {
    iSelectTheSongSongName: function (song_name) {

    },
    iSeeTheLyrics: function () {

    },
    iCanSingTheSong: function () {

    }
};

When I run the above using any of the following commands ...

bash-3.2$ cucumberjs
bash-3.2$ cucumber.js --require=features/step_definitions
bash-3.2$ cucumber.js --require=features/step_definitions/step_definitions.js

I get this error ...

UUU

Warnings:

1) Scenario: Singer sings the lyrics to song # features/Test_Project.feature:7
   ? Given I select the song "Unchain My Heart"
       Undefined. Implement with the following snippet:

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

   ? And I see the lyrics
       Undefined. Implement with the following snippet:

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

   ? Then I can sing the song
       Undefined. Implement with the following snippet:

         Then('I can sing the song', function (callback) {
           // Write code here that turns the phrase above into concrete actions
           callback(null, 'pending');
         });

1 scenario (1 undefined)
3 steps (3 undefined)

What am I doing wrong? I am using the correct expression syntax for version 3.x ... what else can I try?

ra9r commented 7 years ago

I may have figured this out ... very confusing setup requirements with the changes between versions. Near as I can tell I was using a combination of syntax, and not all was correct for the latest. Here is how the step_definitions.js file had to change ...

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

defineSupportCode(function({Then, When, Given, Before, After}) {
    Before(function (scenario) {
        this.actionwords = Object.create(require('./actionwords.js').Actionwords);
    });

    After(function (scenario) {
        this.actionwords = null;
    });

    Given('I select the song {string}', function (song_name, callback) {
        this.actionwords.iSelectTheSongSongName(song_name);
        callback();
    });

    Given('I see the lyrics', function (callback) {
        this.actionwords.iSeeTheLyrics();
        callback();
    });

    Then('I can sing the song', function (callback) {
        this.actionwords.iCanSingTheSong();
        callback();
    });
});
timjroberts commented 7 years ago

Unfortunately @ra9r, CucumberJS 3.0+ isn't supported. The 2.2 release works with CucumberJS 2.2 and the plan would be to release maj.min releases to support that same version of CucumberJS because its API changes quite a lot between releases.

mikehaas763 commented 6 years ago

Has work already began to support cucumber-js 3? We're using that version with this lib, currently casting like @given('{string} clicks the button on tile for account {int}' as any) to use Cucumber Expressions

timjroberts commented 6 years ago

I may try and pick this up in the new year. CucumberJS moves on much quicker than I can keep up though, but I'll do my best. I'm happy to accept PRs too.

KeithGillette commented 6 years ago

cucumber-js is now at version 4.2.1. Any plans to update cucumber-tsflow to support version 4? FWIW, I see there's a much simpler (less feature-rich) FlippieCoetser/Cucumber.Decorators project that supports Cucumber version 3 and version 4 which may provide some guidance on the updates needed to cucumber-tsflow.

mikehaas763 commented 6 years ago

@KeithGillette absolutely! Coming soon 🙂 FYI we’re currently using this lib with cucumber 3. It technically isn’t on the supported list but it absolutely works as is. We just ignore the version warning that npm gives 😬 have you tried to see if it just works with v4 yet?

KeithGillette commented 6 years ago

Awesome, @mikehaas763! I just tried and as soon as I figured out how to change our protractor.cucumber.conf.js cucumberOpts:to no longer use format: ['pretty'] it turns out that our tests worked fine with cucumber-tsflow and cucumber-js@4.2.1. I was already ignoring the DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead., so also ignoring DeprecationWarning: cucumber: defineSupportCode is deprecated. Please require/import the individual methods instead. is not too big of a deal. Thanks!