ts-mocha icon indicating copy to clipboard operation
ts-mocha copied to clipboard

How can I --require .ts files?

Open trgsv opened this issue 2 years ago • 4 comments

Hi, I would like to require a file, so it runs before all of my tests. Example: ts-mocha -r test/setup.ts \"test/**/*.test.ts\"

If I run this I get the following error: TypeError: Unknown file extension ".ts". If I try to run the setup.mjs file, which I had before, when I wasn't using typescript, all the imports in that file don't work, because they are from .ts files.

What's the best way to get this working with ts-mocha?

trgsv avatar May 01 '23 15:05 trgsv

Same here. Seems like a TypeScript test runner should know about .ts files.

pmark avatar May 07 '23 21:05 pmark

I have the same issue. Is there anything new ?

I just decided to move forward and migrated to vitest.

trgsv avatar Jul 01 '23 15:07 trgsv

Same here :(

cope avatar Nov 30 '23 16:11 cope

This error has been a lot in the community. The suggested methods are :

  1. In tsconfig.json , update { "esModuleInterop": true,}
  2. use test script as : "mocha --loader ts-node/esm --timeout 60000 --exit"

However non have worked so well for me

SySagar avatar Mar 01 '24 17:03 SySagar