Balrog994 / cucumber-test-runner

An Extension for Visual Studio Code to Run and Debug CucumberJS Tests
MIT License
4 stars 6 forks source link

Test runner says steps are undefined when official Cubumer extension can navigate between steps and features. #1

Closed jvdwyer closed 1 year ago

jvdwyer commented 1 year ago

Hello. When trying this extension and running/debugging scenarios the test running says "Undefined. Implement with the following snippet". But when I run using cucumber-js script cucumber is able to link the feature file with step file and run the tests. Here is my cucumber.js file:

const dotenv = require('dotenv');

dotenv.config({override: false});

let options = [ '--require-module ts-node/register', '--require ./srs-vp/System-Requirement-Specifications/Functional-Requirements/steps/*steps.ts', '--format progress', ].join(' ');

let run_features = [ './srs-vp/System-Requirement-Specifications/Functional-Requirements/features/*.feature', options, ].join(' ');

module.exports = { test_runner: run_features };

Here is my settings.json:

{ "cucumberautocomplete.strictGherkinCompletion": true, "cucumberautocomplete.steps": [ "./doc/srs-vp/System-Requirement-Specifications/Functional-Requirements/steps/.ts" ], "cucumberautocomplete.syncfeatures": "./doc/srs-vp/System-Requirement-Specifications/Functional-Requirements/features/.feature", }

Balrog994 commented 1 year ago

Hi, I'll look into it in the weekend 👍

Balrog994 commented 1 year ago

Your main issue is due to a missing feature of this extension. The extensions launches tests with the default profile, your configuration file exports a profile named test_runner.

To solve this problem you have to change your cucumber.js config as follows (until I add the feature)

module.exports = {
-  test_runner: run_features
+  default: run_features,
};

This however brings up a new problem that's actually mentioned in the following issue cucumber/cucumber-js#2253 on the cucumber-js repository.

I think I have a workaround until cucumber-js implements better support for cli arguments. You can change your cucumber.js file as follows:

const dotenv = require("dotenv");

dotenv.config({ override: false });

let options = [
  '--require-module ts-node/register',
  '--require ./srs-vp/System-Requirement-Specifications/Functional-Requirements/steps/*steps.ts',
  '--format progress',
].join(" ");

- let run_features = ['./srs-vp/System-Requirement-Specifications/Functional-Requirements/features/*.feature', options].join(" ");
+ //let run_features = ['./srs-vp/System-Requirement-Specifications/Functional-Requirements/features/*.feature', options].join(" ");

module.exports = {
-  default: run_features,
+  default: options,
};

This allows the extension to launch the tests correctly.

Hope this helps 😉

jvdwyer commented 1 year ago

Thanks for the response. I made changes (below) to cucumber-js but am still seeing the same behavior. When I run using cucumber-js script cucumber is able to link the feature file with step file and run the tests but cucumber-test-runner reports that the steps are undefined.

cucumber-js:

const dotenv = require('dotenv');

dotenv.config({ override: false });

let options = [ '--require-module ts-node/register', './srs-vp/System-Requirement-Specifications/Functional-Requirements/features/.feature', '--require ./srs-vp/System-Requirement-Specifications/Functional-Requirements/steps/steps.ts', '--format html:cucumber-report/cucumber-report.html', '--publish-quiet' ].join(' ');

module.exports = { default: options, };

Balrog994 commented 1 year ago

Hi,

I guess your problem is the following line:

'./srs-vp/System-Requirement-Specifications/Functional-Requirements/features/*.feature',

If you keep that line in the configuration, the extension will not work properly due to the problem mentioned before. You need to remove the path to your *.feature files, the extension will discover the files on its own and launch the proper test.

If you need both the configurations, you can try to define 2 profiles, the default one for the extension and another one to launch the tests from the CLI.

jvdwyer commented 1 year ago

Hello again. I took your suggestion and created multiple profiles but the behavior is the exact same:


dotenv.config({ override: false });

const common = {
    requireModule: ['ts-node/register'],
    require: ['./srs-vp/System-Requirement-Specifications/Functional-Requirements/steps/*steps.ts'],
    publishQuiet: true
}

const paths = [
    './srs-vp/System-Requirement-Specifications/Functional-Requirements/features/*.feature'
]

module.exports = {
    default: {
        ...common,
        format: ['html:cucumber-report/cucumber-report.html', 'progress'],
    },
    cli: {
        ...common,
        format: ['html:cucumber-report/cucumber-report.html'],
        paths,
    }
};
Balrog994 commented 1 year ago

Seems like I can't reproduce your problem, just for debug purposes that's what the extension executes to run tests:

node ./node_modules/@cucumber/cucumber/bin/cucumber.js <full-path-to-feature-file>:<line-of-the-selected-test> [...<full-path-to-feature-file>:<line-of-the-selected-test>] --format message

The command is executed from the working folder open in VSCode. You may try to run the same line from your terminal and check if you get the same behavior.

I tried your new configuration in my test project and, aside from manually creating the cucumber-report folder, I had no problems, the extension ran the tests correctly.

I would be great if you could publish a minimal project that exposes this behavior 😉