cucumber / language-service

Cucumber Language Service
MIT License
12 stars 21 forks source link

Unable to locate Javascript steps generated from building Typescript files #187

Open Billy-Stroud opened 2 months ago

Billy-Stroud commented 2 months ago

πŸ‘“ What did you see?

I am using the VSCode Cucumber plugin within a Typescript project that imports common shared steps from a Typescript npm module that is packaged as Javascript.

The plugin is able to successfully locate step definitions in Typescript from the local src code, but it fails to locate the shared Javascript steps from the dependency. This seems to be due to the regular expression for matching Javascript step definitions not working for Javascript files that were transpiled down from Typescript. Here's an example of what one of my steps looks like after it has been built into Javascript:

const cucumber_1 = require("@cucumber/cucumber");
(0, cucumber_1.Given)(/^I login$/, function () {
    return __awaiter(this, void 0, void 0, function* () {
        yield this.login();
    });
});

This seemed like it could be fixed by overriding TSX's defineStepDefinitionQueries value in the Javascript implementation to look for Given|When|Then|Given)|When)|Then) however I get Invalid regular expression: Unmatched ')' errors when testing with it even if I try to escape the parentheses. I wasn't really sure what else to try in this case.

Any help would be greatly appreciated!

βœ… What did you expect to see?

Expected the plugin to find the Javascript steps.

πŸ“¦ Which tool/library version are you using?

πŸ”¬ How could we reproduce it?

Steps to reproduce the behavior:

  1. Create a JS file with the following data:
    "use strict";
    var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
    };
    Object.defineProperty(exports, "__esModule", { value: true });
    const cucumber_1 = require("@cucumber/cucumber");
    (0, cucumber_1.Given)(/^I login$/, function () {
    return __awaiter(this, void 0, void 0, function* () {
        yield this.login();
    });
    });
  2. Check the Cucumber Language Server output to see if it picks up the new step

πŸ“š Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

barrymichaeldoyle commented 1 month ago

I was having the same problem.

This PR seems to fix it for my projects:

https://github.com/cucumber/language-service/pull/186/files