I was following a tutorial but the setup is really bad. Basically it uses typescript to convert .ts files to .js. So basically pollutes your whole source code with .js files around.
So as soon as you import your .ts file from source code, all dependencies are duplicated with a .js file.
Do you know how to do proper typescript cucumber tests?
A hacky solution: Copy all features and all files to another temp folder, run from there. I would expect cucumber to be a bit more mature than this, hence my question here?
Or change the configuration of cucumber to look in the build folder from ts.
Thank you
Code structure:
Now you will compile the typescript and have this structure:
Now you can see that stepDefinitions.js
has no idea where to find a.feature
. If you run cucumber on the build/test folder it won't find any step feature to run... because well, they are in the tests folder. So the hacky way to fix it is to copy over the features files resulting this structure:
Now it will work but is hacky, I don't like it.
js suite using TypeScript and cucumber-tsflow. Cucumber-tsflow is a package that will allow us to take advantage of TypeScript's decorators, which make for clearer step definition code. experimentalDecorators must also be set to true in your tsconfig. json in order for the decorators to compile properly.
Cucumber. js is available as an npm module. It works with both Node. js and browsers.
Install Cucumber-Quick Cucumber-Quick is a VSCode extension that helps you to run cucumber scenarios and features directly from VSCode editor. You can simply right-click on any feature file and choose the option from the context menu to run a specific scenario or the whole feature file.
Updated answer based on more info provided:
The first thing you should do is separate your features and steps into their own folders
tests
features
a.feature
b.feature
stepDefinitions
aStep.ts
Next, create a cucumber.js file which will be the cucumber profile. I use the following profile but it's up to you what you want to do
var common = [
`--format ${
process.env.CI || !process.stdout.isTTY ? 'progress' : 'progress-bar'
}`,
'--format json:./reports/cucumber-json-reports/report.json',
'--format rerun:@rerun.txt',
'--format usage:usage.txt',
'--parallel 20',
'--require ./build/tests/stepDefinitions/**/*.js',
'--require ./build/tests/stepDefinitions/*.js',
'--require ./build/tests/support/*.js'
].join(' ');
module.exports = {
default: common,
};
The above tells cucumber where your steps are. Now you can run something like the following from the root of the project
tsc && ./node_modules/.bin/cucumber-js ./tests/features/ -p default
This will
Edit: See https://stackoverflow.com/a/55378059/3323395 for how to do this without needing to compile first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With