typescriptpluginswebstormes6-modulescucumberjs

Unable to make Cucumber plugin in WebStorm IDE to work for test steps written in TypeScript with on-the-fly ESM transpilation


I don't find a way to correctly configure the Cucumber plugin in WebStorm IDE to work with my TypeScript configuration.

The setup I would like is the following:

I have been able to set up correctly CucumberJs through CLI with the following configuration (with Node.js v19.7.0):

{
  "name": "Test config",
  "version": "1.0.0",
  "description": "",
  "main": "src/calculator.ts",
  "scripts": {
    "test1": "SET NODE_OPTIONS=--loader ts-node/esm --no-warnings --experimental-specifier-resolution=node && cucumber-js",
  },
  "type": "module",
  "devDependencies": {
    "@cucumber/cucumber": "8.11.1",
    "@types/node": "18.13.0",
    "ts-node": "10.9.1",
    "typescript": "4.9.5"
  }
}
{
  "default": {
    "paths": ["src/*.feature"],
    "import": ["src/support/*.steps.ts"],
    "parallel": 1,
    "format": ["html:cucumber-report.html"],
    "publishQuiet": true
  }
}

Alas, when I run the feature file through the Cucumber plugin with the following environment variables configured, NODE_OPTIONS=--loader ts-node/esm --no-warnings --experimental-specifier-resolution=node I get the following error:

"C:\Program Files\nodejs\node.exe" C:\Users\DS\WebstormProjects\cc2\node_modules\@cucumber\cucumber\bin\cucumber-js C:\Users\DS\WebstormProjects\cc2\src\calculator.feature esm --format C:\Users\DS\AppData\Local\JetBrains\Toolbox\apps\WebStorm\ch-0\223.8617.44\plugins\javascript-cucumber\lib\cucumberjs_formatter_v7.js --format-options "{\"cucumberLibPath\": \"C:/Users/DS/WebstormProjects/cc2/node_modules/@cucumber/cucumber/lib\"}" --format-options "{\"colorsEnabled\": true}" --publish-quiet --require C:/Users/DS/WebstormProjects/cc2/src
Testing started at 01:22 ...
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for C:\Users\DS\WebstormProjects\cc2\node_modules\@cucumber\cucumber\bin\cucumber-js
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:74:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:114:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at C:\Users\DS\WebstormProjects\cc2\node_modules\ts-node\src\esm.ts:255:45
    at async addShortCircuitFlag (C:\Users\DS\WebstormProjects\cc2\node_modules\ts-node\src\esm.ts:409:15)
    at async nextLoad (node:internal/modules/esm/loader:163:22)
    at async ESMLoader.load (node:internal/modules/esm/loader:597:20)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:449:11) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

Process finished with exit code 1

As soon as I rename the C:\Users\DS\WebstormProjects\cc2\node_modules\@cucumber\cucumber\bin\cucumber-js file to [..]\cucumber-js.js, then the plugin work without any problem. Thankfully, then CLI command continue to work too after such modification.

I am not confident at all that manually renaming a file in the node_module folder won't break something in a near future when I will have totally forgotten this exotic manipulation...

Does anyone know another way to fix this strange behaviour?


Solution

  • Upgrading the package @cucumber/cucumber and NodeJs to their last versions (respectively 9.0.1 and 19.8.1) did the trick.

    Alas, I have no idea why...