using a tsconfig.json file with cucumber-js

See original GitHub issue

When using cucumber-js with TypeScript, I can’t figure out how to get a tsconfig.json to take effect.

cucumber version: 5.0.0 node version: v8.11.3 os: OS X El Capitan 10.11.6

At my project’s root, I’ve got a package.json that contains:

{
  "name": "...",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test-features": "cucumber-js test/features --require-module ts-node/register --require 'test/features/**/*.ts'",
    ...

Also at project root, a tsconfig.json file that contains something like:

{
  "compilerOptions": {
    "baseUrl": ".", // This must be specified if "paths" is.
    "paths": {
      "*": [
        "src/commands/*"
      ] // This mapping is relative to "baseUrl"
    }
  }
}

To run cucumber, I type npm run test-features

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
adamf321commented, Feb 23, 2022

In case any else stumbles upon this trying to get baseUrl to work with ts-node / cucumber-js…

You need to create a setup file:

// cucumber.setup.js

require("ts-node").register({
  transpileOnly: true,
  require: ["tsconfig-paths/register"],
  compilerOptions: {
    "module": "commonjs",
    "resolveJsonModule": true,
    "baseUrl": ".",
  },
});

require: ["tsconfig-paths/register"] was the part which tripped me up.

Then reference it in your cucumber config file:

// cucumber.js

module.exports = {
  default: [
    "--require cucumber.setup.js",
    "--require tests/bdd/**/*.ts",
    "--publish-quiet",
  ].join(" "),
};
3reactions
scotch83commented, Sep 24, 2020

@arjunjh10

“cucumber”: “ts-node --project <ts-config.json file location> cucumber-runner.ts”,

I am interested to hear how such a file would look like

Read more comments on GitHub >

github_iconTop Results From Across the Web

example of cucumber-js with babel and es6? - Gitter
Hi, I'm using cucumber-js with Typescript and am noticing that when I run my code via cucumber-js, the tsconfig.json file is not read....
Read more >
Cucumber.js with TypeScript - Elliot DeNolf
This post will go through setting up a basic Cucumber.js suite using ... your tsconfig.json in order for the decorators to compile properly....
Read more >
TypeScript Module Resolution doesn't quite work with ...
So far everything is fine...but I can't find a way to properly configure the module resolution when using tsconfig-paths . This is my...
Read more >
Running Cucumber test written in TypeScript from WebStorm
Here's an example of tsconfig.json , feel free to adjust it to your ... and choose Cucumber.js; Feature file or directory , leave...
Read more >
Cucumber.js | WebStorm Documentation - JetBrains
json file to use. WebStorm will run the TypeScript compiler with this tsconfig.json before running Cucumber.js. Cucumber.js Run configuration: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found