Cucumber-js: Please add support for TypeScript

Created on 13 May 2015  ·  33Comments  ·  Source: cucumber/cucumber-js

I created a lib with typescript and my tests are written in typescript too. I really would like to try cucumber.js and create step definition files, with typescript. So you support coffeescript and js, .ts would be nice too.

Regards

Chris

Most helpful comment

@jbpros since the readme's been updated, and this shows prominently in results for "cucumber typescript", an excerpt:

Transpilers

-Step definitions and support files can be written in other languages that transpile to javascript.
-This done with the CLI option --compiler <file_extension>:<module_name>. For CoffeeScript 1.10.0,
-this is done with --compiler coffee:coffee-script/register.
Step definitions and support files can be written in other languages that transpile to javascript. This done with the CLI option --compiler <file_extension>:<module_name>.

CoffeeScript

Install the coffee-script NPM package and invoke Cucumber with --compiler coffee:coffee-script/register.

TypeScript

Install the typescript-node NPM package and invoke Cucumber with --compiler ts:typescript-node/register.

As usual, all your step definition and support files must export a function to be run by Cucumber. This is how it is done in TS:

declare var module: any;
module.exports = function () {
 this.Given(/.*/, function () {
   // ...
 })
}

PogoScript

Install the pogo NPM package and invoke Cucumber with --compiler pogo:pogo.

All 33 comments

Why don't you send a pull request @Chris2011

I will be only a customer of this project, when I do each pull request of each stuff what I use and there is some missing, than I can create it by my own. It is only a feature request. If someone has time and would like to do it, why not. Me not, because I don't have time, I have the same normal work and other projects and don't want to be a contributor on each project that I use. Sry for the harsh words maybe but for me it is clear that it is not possible to be a contributor on each project, what I use. I have to understand the source and so on.

I understand @Chris2011. Maybe one day someone will decide to spend time implementing this because they want to help you, or just for fun.

The more realistic scenario is that this feature request stays open until someone needs it enough to be willing to spend the time and effort to implement it and send a PR.

Maybe. Thx for your opinion. In my perspective, it was only logic to ask for this feature because TS will be more popular as for 1 or 2 years. And when you or whoever decided to implement coffeescript too, why not typescript too?

Thx a lot. We will see what happens...

In general - just like formatters - I'd like to have language/dialect support to be 3rd party plugins instead of part of the core (including the current CoffeeScript and PogoScript).

TS +1

+1

Like it, pls do it some time!!!

:+1:

No amount of +1 or :+1: will make this happen. Someone has to submit a pull request.

:+1: @aslakhellesoy spot on

:8ball: @samccone

@jbpros @aslakhellesoy the only thing should be done to support 3rd party languages is implementing way to modify:

SupportCodePathExpander.SUPPORT_CODE_FILES_IN_DIR_REGEXP = /\.(js|coffee|pogo)$/;

And then anyone can register any transpiler in support/env.js for example
maybe this regex should be removed at all?

I'm happy to look at this. I can find the coffeeScript feature file but can't find where the step definitions are implemented, please could someone give me some pointers as to what needs to be done?

@SeanFarrow I've already done it locally. You have just to modify /lib/cucumber//cli/argument_parser/support_code_path_expander.js:12 and then add any transpiler via require hook

Are you ghoing to send a pr?

From: Aleh Kashnikau [mailto:[email protected]]
Sent: 16 August 2015 19:15
To: cucumber/cucumber-js [email protected]
Cc: Sean Farrow sean.[email protected]
Subject: Re: [cucumber-js] Please add support for TypeScript (#335)

@SeanFarrowhttps://github.com/SeanFarrow I've already done it locally. You have just to modify /lib/cucumber//cli/argument_parser/support_code_path_expander.js:12 and then add any transpiler via require hook


Reply to this email directly or view it on GitHubhttps://github.com/cucumber/cucumber-js/issues/335#issuecomment-131598410.

@mkusher there is more to it. To be complete, step definitions snippets should also be available in the additional language (which is currently not done for PogoScript), see the CLI --coffee flag.

I'd really like this to be done via a plugin/transpiler system anyway and remove all dialects from core (including coffeescript).

I don't understand why language specific support is even needed? Wouldn't you just transpile the step definitions to JavaScript as part of your build process?

398 should make supporting any transpiler simple

Yep, #398 will fix this.

@henrify the only thing that "needs" to be added to Cucumber is the step definition snippet support for other languages. Currently they're in vanilla JS by default and can be output in CS with the --coffee CLI flag.

We might just drop non-JS snippets altogether (including CS?). Thoughts?

398 has been merged and will be available in the next release. TypeScript support is documented in the README.

@jbpros since the readme's been updated, and this shows prominently in results for "cucumber typescript", an excerpt:

Transpilers

-Step definitions and support files can be written in other languages that transpile to javascript.
-This done with the CLI option --compiler <file_extension>:<module_name>. For CoffeeScript 1.10.0,
-this is done with --compiler coffee:coffee-script/register.
Step definitions and support files can be written in other languages that transpile to javascript. This done with the CLI option --compiler <file_extension>:<module_name>.

CoffeeScript

Install the coffee-script NPM package and invoke Cucumber with --compiler coffee:coffee-script/register.

TypeScript

Install the typescript-node NPM package and invoke Cucumber with --compiler ts:typescript-node/register.

As usual, all your step definition and support files must export a function to be run by Cucumber. This is how it is done in TS:

declare var module: any;
module.exports = function () {
 this.Given(/.*/, function () {
   // ...
 })
}

PogoScript

Install the pogo NPM package and invoke Cucumber with --compiler pogo:pogo.

Is it really needed to use typescript-node? Is it possible to use the official supported tsc instead of typescript-node? I don't know the differences but tsc is official supported from Microsoft.

@Chris2011 ts-node is just a register hook for node.js that will run compilation via tsc

Ok thx.

@JoshuaKGoldberg where is the excerpt from? My searches have failed to find it.

A sample to guide you in the cucumberjs with typescript use:
https://github.com/AbraaoAlves/cucumber-protractor-typescript-boilerplate

Thanks @AbraaoAlves for the sample.
Unfortunately, it only works with cucumberjs 1. The protractor-cucumber-framework layer is not compatible with the cucumber2 rcs.

how to attach screenshot in cucumber report. I'm using typescript language. Please anyone help me.

Please confirm if there would be cucumber+Protractor+Typescript compatibility issues going forward...as we plan use the combination for our implementations..

@Rajazpandi
Do something like this in After

driver.takeScreenshot().then(data => {
        attach(new Buffer(data, 'base64'), 'image/png');
      }).catch(error => {
        info(error);
        throw error;
      });

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings