Reputation: 2489
I am having problems setting up WebStorm with Mocha/Chai and TypeScript.
I installed mocha and chai setup a test script in my package.json
like so
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'tests/**/*.ts'"
When I run npm test
the test runs and everything is fine.
However WebStorm does not recognize describe
and it
. Even though I am running WebStorm 2020.3 I followed the solution in this post without any success.
Furthermore when I use the runner in WebStorm I get the following error:
ERROR: Error: Cannot find module 'ts-node/register'
In the Runner configuration in WebStorm I added the following:
env TS_NODE_COMPILER_OPTIONS='{"module": "commonjs" }'
mocha -r ts-node/register
However this also did not help.
What am I missing?
[Edit]
Thanks to the comment by lena I found out that the Mocha package was pointing to the wrong project so I fixed it. Unfortunately I now get this error:
Upvotes: 3
Views: 798
Reputation: 93848
Try changing the way your environment variable is defined - remove the single quotes around the value, this is what mocha is complaining about. Just set it to TS_NODE_COMPILER_OPTIONS={"module":"commonjs"}
:
it works fine for me
Upvotes: 3