testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Add support for TypeScript configuration file

Open Halllker opened this issue 3 years ago • 6 comments

What is your Scenario?

TestCafe with TypeScript is so far a great experience, however there is an issue with global hooks and configuration file.

Global hooks can be defined only with JS configuration file which restricts from importing TypeScript classes and functions. This makes global hooks nearly impossible to use without some solid dark magic.

What are you suggesting?

Please, add a support for TypeScript configuration file so TS code can be referenced in global hooks and similar functionality (if any).

What alternatives have you considered?

Other possibility would be to separate global hooks from configuration files completely, which would maybe feel a bit more natural and there would be no need for js or ts config files and everything necessary could be handled by simple json.

Additional context

No response

Halllker avatar Nov 08 '22 10:11 Halllker

And of course right after I've created this issue I stumbled upon similar one that approaches basically the same problem from the other side. https://github.com/DevExpress/testcafe/issues/6867

Halllker avatar Nov 08 '22 10:11 Halllker

Hi @Halllker,

Thank you for the suggestion. We'll update this thread once we have any news.

Aleksey28 avatar Nov 09 '22 07:11 Aleksey28

This enhancement would be great! I had similiar issues so I just went with .testcaferc.json for the configuration, and I created my own re-usable classes to handle repeating stuff. This would solve many issues for sure, thumbs up!

gforepsly avatar Nov 09 '22 08:11 gforepsly

While we wait for the exciting PR to get merged. Is there a type annotation I can add in a comment in the .testcaferc.js file to get some type support for configuration options. Most tools I use support typescript config files and I immediately miss type support for exploring configuration options (and validating them) and am a little annoyed by having to visit the documentation every time I want to tweak or add something.

I tried looking through the source code to find a type definition for the config file contents, but I am not actually sure that one exists at this point...

Jackman3005 avatar Feb 21 '24 07:02 Jackman3005

@Jackman3005 this works for me:

/** @type {TestCafeConfigurationOptions} */
module.exports = {

Klaster1 avatar Feb 21 '24 09:02 Klaster1