cypress-select-tests icon indicating copy to clipboard operation
cypress-select-tests copied to clipboard

[Question] Does cypress-select-tests support Typescript?

Open git-malu opened this issue 4 years ago • 15 comments

I guess cypress-select-tests does not support Typescript so far. Because when I try to use cypress-select-tests together with Typescript, I get the error below.

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (17:0)

My Cypress package works well with Typescript if I comment out this plugin.

// on('file:preprocessor', selectTestsWithGrep(config));

git-malu avatar Jun 17 '20 08:06 git-malu

+1, facing the same issue

sagar-ganatra avatar Jun 29 '20 06:06 sagar-ganatra

@bahmutov any chance you can do a quick fix? Seems like a handful of us are having this issue

csalazar1 avatar Jul 01 '20 01:07 csalazar1

It wasn't a quick fix. The library uses falafel to parse the source code and rewrite steps with .skip. I have swapped it to use the typescript compiler (which will of course read javascript) and rewrite it in the same fashion, but it also needs to turn typescript on as this library wipes out the normal cypress ability to process typescript.

rvowles avatar Aug 04 '20 20:08 rvowles

@rvowles was this merged to master already?

csalazar1 avatar Aug 04 '20 20:08 csalazar1

No, I haven't pushed it up and I don't think @bahmutov will want it given it swaps from falafel to typescript. Its currently under review where I work.

rvowles avatar Aug 04 '20 20:08 rvowles

Got it. Thank you so much for the update on this

csalazar1 avatar Aug 04 '20 20:08 csalazar1

Ok @csalazar1 - my "branch" is over here but I'm not issuing a PR because I don't think @bahmutov will be that interested. https://github.com/rvowles/cypress-select-tests

It does a few things - it always enables typescript, it uses a ts parser for typescript and javascript one for javascript. We only use typescript here, so I left the js one for the tests.

Further it has a preprocessor that reads the cypress.json file, applies your filtering and updates the cypress.json file into a cypress-grep.json file, which then includes the filtering but removes any files in your spec list that wouldn't be run as they have no tests.

One thing you probably won't like is that it actively removes tests that are not run rather than leaving them pending. Pending on our case implies there is some action that needs to be done on them, confusing the reporting. In typescript, this removes the step and replaces it with a placeholder ("true").

rvowles avatar Aug 10 '20 22:08 rvowles

@rvowles I finally got around to this. It seems to be failing with this error though error

Any ideas what it could be?

csalazar1 avatar Sep 28 '20 02:09 csalazar1

If it is acorn your issue is that it is treating whatever that file is as JavaScript and parsing it using acorn and falafel.

rvowles avatar Sep 28 '20 02:09 rvowles

@rvowles we're trying to use your plugin, stock standard config (i.e. on('file:preprocessor', selectTestsWithGrep(config));) and we keep getting SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' no matter what we change. We've tried messing with tsconfig files but nothing seems to work. How do we tell this thing that we are using typescript files? It's like it isn't finding our tsconfig file (which is in the cypress directory)

biltongza avatar Oct 23 '20 10:10 biltongza

Maybe ask this question on my repo instead of here?

rvowles avatar Oct 23 '20 20:10 rvowles

image you don't have Issues enabled on your repo :(

biltongza avatar Oct 26 '20 16:10 biltongza

Any update ?

onimougwo avatar Feb 25 '21 14:02 onimougwo

I would love Typescript to be supported by this plug-in. Thanks for all the hard work on this one!

estefafdez avatar Mar 19 '21 21:03 estefafdez

Does anyone was able to resolve this error SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'? If yes, please guide how did you do.Really appreciate. Thank you.

NeetuHundal avatar Apr 29 '21 04:04 NeetuHundal