rewire icon indicating copy to clipboard operation
rewire copied to clipboard

Rewire doesn't work with typescript

Open KaboomFox opened this issue 4 years ago • 4 comments

[Feature request] Support Tyescript.

Rewire cannot find files that have extension .ts or .tsx

KaboomFox avatar Jul 17 '20 20:07 KaboomFox

as a workaround, you might be able to try compiling your ts to js in the interim @KaboomFox

aubreyyan avatar Jul 22 '20 03:07 aubreyyan

@KaboomFox I had this problem a few weeks ago. I recommend taking a look at https://github.com/kulshekhar/ts-jest/issues/1029. Using ts-jest with ts-node, you should be able to make it work.

I ultimately decided not to use rewire since there is an open issue about it messing up code coverage reporting, but perhaps that is not an issue for you.

TheJizel avatar Aug 03 '20 01:08 TheJizel

I have tried this module with success in my Typescript project. In fact, types even exist for this https://www.npmjs.com/package/@types/rewire.

There wasn't any special configuration required. I'm using mocha and my config is:

--exit
--require ts-node/register/transpile-only
--timeout 30000
--bail
test/*.{ts,js}

20k-ultra avatar Jan 21 '21 01:01 20k-ultra