Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Billy-Stroud opened this issue Mar 4, 2024 · 1 comment
Labels
🐛 bug Defect / Bug

Comments

@Billy-Stroud
Copy link

👓 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?

  • Cucumber VSCode plugin: v1.8.1
  • Node: v18.17.1
  • Typescript: v5.3.3
  • Cucumber: v9.6.0

🔬 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();
    });
});
  1. 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
Copy link

I was having the same problem.

This PR seems to fix it for my projects:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

3 participants