-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
using a tsconfig.json file with cucumber-js #1139
Comments
In one of the Cucumber Projects in my org, what I did was have a so in my package.json:
hope it helps |
Does your |
Use latest I guess it is worth of it to add that into README ;-)
cucumber run:
folder structure:
tsconfig.json:
|
As far as I remember, in this context ts-node would expect the tsconfig to be in the test folder. You could try creating a config in the test folder that extends the one in the root folder or setting the TS_NODE_PROJECT environment variable. |
Any updates on this one? I'm also trying to setup something similar, and while it works for the most part, I still have some issues when using Funny thing is, if I delete the |
@x80486 did you have any luck with |
@jackall3n, I can't remember right now. I had to move to some other project. Let me see if I can go back to try this one again with newer versions of Cucumber.js...probably something changed 🙄 |
Closing this due to inactivity. Will be happy to re-open if more details provided. |
@Izhaki, the details are on the issue. For instance, if you want to reproduce this, grab this project and change the following in
...then execute |
I am interested to hear how such a file would look like |
@arjunjh10 I am also interested in the content of your |
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:
Then reference it in your cucumber config file:
|
Note that there's now a TypeScript reference example, here. |
Yes, I saw that. But it uses relative module imports so doesn't show how to solve this problem. It's more of a ts-node quirk than a Cucumber issue specifically. |
I am using NX for my monorepo, it works well, but when i import something from my local libs it tell me cannot find module "My Local Lib Name" , the problem is not with NX because it works fine with other stuff but not with cucumber-js. My local libs paths are defined in my tsConfig. How can i solve this issue? |
@MarufSharifi To be honest, this is not an issue with CucumberJS. This is about module resolution, monorepos, build configurations. StackOverflow may be a better place to ask these questions. Anyhow, it is impossible to say without more details. As a pointer, whatever transpile your code when running cucumber should be configured to account for aliases (aka You'll need to provide more details on how exactly the transpilation of your code is set up in cucumber. |
Hi, Thanks for reply, This is my babel transpiling config apps/web/brands-e2e/init.ts This is init.ts file code
I can easly switch to ts-node if it helps. what else do i have to add? |
tsConfig works fine in compile time, it know that we have those local libs, but in runtime it doesn't work, it tell me I cannot find this module. I mean it suggest me those local libs when importing them. I asked from NX community as well, they told me, "You may need a flag to tell the CLI you are calling what tsconfigs to use" |
There is a bit more degree of freedom with babel, you can try:
That should give you an idea. Or just use |
Finally I solved the problem, just added babel-plugin-tsconfig-paths to my babel configuration |
In case someone wants a solution that doesn't require using /**
* Calls cucumber-js and overrides default tsconfig.json
*/
const { spawn } = require("child_process");
const cli = "npx cucumber-js --config src/app/cucumber.js";
const [command, ...args] = cli;
const env = {
// all existing process environment variables
...process.env,
// This is required since `ts-node/register`
// defaults to using the root tsconfig.json of the project
// and the problem is that Nx provides several tsconfig files
//
// Also Cucumber doesn't offer a way to set this for ts-node
// You can override ts-node's behavior using this environment variable
TS_NODE_PROJECT: "src/app/tsconfig.json",
};
spawn(command, args, {
env,
// Sends output from child process to parent process
stdio: "inherit"
}); For reference, here is my cucumber configuration: module.exports = {
default: {
parallel: 1,
requireModule: ['ts-node/register'],
publishQuiet: true,
format: [
'html:dist/cucumber/app/cucumber-report.html'
],
paths: ['src/app/src/features/**/*.feature'],
require: ['src/app/src/step-definitions/**/*.ts'],
},
}; |
this made it work to me
|
Is there a way to do this for Windows? |
Not sure about what the cucumber-runner.js contains but it could be a link to This is how i solved the issue of using having a project with module: ESNext and needing a separate tsconfig with CommonJS to run cucumber. (npm run automation) We have a react app with standard ./src folder and has a subfolder with features and step-definitions. This subfolder also holds
|
I had some problems while configuring cucumber to run with typescript and using dedicated tsconfig file, so I want to add some information here :
Note : in my case, the error was coming from the line |
Thanks for sharing @delairec - feel free to send a PR updating the existing example or adding a new one: https://github.com/cucumber/cucumber-js-examples/tree/main/examples/typescript-node |
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:Also at project root, a
tsconfig.json
file that contains something like:To run cucumber, I type
npm run test-features
The text was updated successfully, but these errors were encountered: