protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Typescript support

Open aleks-sidorenko opened this issue 12 years ago • 15 comments

Is there a way to write tests in typescript without compiling it manually before testing? Some kind of typescript preprocessor? I know it is possible to write tests in coffee, is it possible to do same with typescript?

aleks-sidorenko avatar Aug 18 '14 16:08 aleks-sidorenko

At the moment, we have no special support for this. I'd be happy to take a look at a PR adding functionality if someone was interested.

juliemr avatar Aug 18 '14 21:08 juliemr

Aleks, What's is your exact problem with running the compiler? We are writing our tests with typescript, compiles them automatically to javascript, and running them on protractor.

omer727 avatar Oct 01 '14 08:10 omer727

Hi all ! I don't know if this is the right place to write down this question, but I'm having some problems to run tests writen using Typescript in different classes. I want to abstract some common parts of all my test to a base test class, and then extend it from my spec files. Everything compiles correctly, but it fails when executes js files, where the prototype is not defined.

Any help on this ?

ghost avatar Mar 11 '15 18:03 ghost

Should be "Typescript support" or "Typescript rewrite"? Given angular 2.0 will be in TS maybe Protractor should be fully rewritten in TS ;)

elgalu avatar Nov 20 '15 13:11 elgalu

@elgalu maybe, but for now, we can create definitions files from jsdoc. With this https://www.npmjs.com/package/typescript-closure-tools

In my typescript projects I use tsd to manage my definitions files, includes angular-protractor. The big problem in definition files is that they are part of project independent, although they were always synchronized, even if manually!

A tool to generate here a "protractor.d.ts" will be great help for everyone.

AbraaoAlves avatar Dec 18 '15 15:12 AbraaoAlves

Update here - I think a typescript rewrite is probably a far-future goal, that wouldn't give us a lot of immediate benefit.

However - we should absolutely include typescript definition files in our package. That's a high priority.

juliemr avatar Jan 04 '16 19:01 juliemr

And what about a typescript preprocessor to be able to write definitions in typescript instead of ES5 js ? Or at least a babel preprocessor for some ES6?

ocombe avatar Jan 04 '16 19:01 ocombe

It looks like we'll need the following definitions to write protractor tests in typescript: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/angular-protractor/angular-protractor.d.ts https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/jasmine/jasmine.d.ts https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node/node.d.ts @juliemr is there much need in the community to write tests in typescript? I definitely understand the little benefit from rewriting protractor in ts, but I'm also not seeing anything in the community on benefits of writing tests in ts, let alone successful implementation. Thanks.

mccataldo avatar Jan 20 '16 00:01 mccataldo

Assuming this issue is about support for specs written in typescript - it would be nice with a preprocessor feature like karma offers in conjunction with browserify. This is current possible with a karma.conf as follow:

module.exports = function(config) {

    config.set({
        ...
        frameworks: ['browserify', 'jasmine'],

        browserify: {
            debug: true,
            plugin: [['tsify', {
                noImplicitAny: true,
                target: 'ES5',
                module: 'commonjs'
            }]],
            bundleDelay: 1000
        },

        files: [
            'unit/**/*.spec.ts'
        ],

        preprocessors: {
            'unit/**/*.ts': ['browserify'],
        },
        ...

plz correct me if I'm on a completely wrong track...

pellekrogholt avatar Jan 21 '16 14:01 pellekrogholt

Something like @pellekrogholt outlined, as a pre-processor for TS would be awesome for anyone interested in using TS with Protractor, for now. Similar to: https://github.com/sergeyt/karma-typescript-preprocessor supporting typings too.

magicode118 avatar Feb 08 '16 08:02 magicode118

Some-how I could debug protractor tests from IDE (I use IntelliJ) written in pure js. Any ideas how to debug specs written in ts and converted "on-the-fly" to js?

DOrlov77 avatar Apr 05 '16 17:04 DOrlov77

Remaining work item: #3169

juliemr avatar Apr 26 '16 01:04 juliemr

As a side note - we are specifically avoiding having preprocessors for Protractor in the line of the Karma plugins which replicate parts of the build process. You should just point Protractor at your generated .js files, and use your normal build pipeline to handle creating those.

juliemr avatar Apr 26 '16 01:04 juliemr

Closing this issue since remaining work is better captured in #3169

juliemr avatar Apr 26 '16 01:04 juliemr

To answer the original question: activating ts-node in a protractor.conf.js file with require('ts-node').register({ allowJs: true }) enables the use of TypeScript for all further dependencies, including spec files. (It's worth setting allowJs to true, to be able to omit the *.ts suffix when requiring/importing a module.)

If you use ts-node together with Protractor, make sure you disable Protractor's source-map-support with skipSourceMapSupport: true in your config, as ts-node brings along its own one and as the two would conflict (at this point in time).

renehamburger avatar Jan 14 '18 16:01 renehamburger