hbenl / vscode-mocha-test-adapter

Mocha Test Adapter for the VS Code Test Explorer
MIT License
91 stars 31 forks source link

Test adapter doesn't build typescript source code #161

Closed rallets closed 3 years ago

rallets commented 3 years ago

Hi, I'm using typescript and Mocha test adapter to run some unit tests in VS Code, it's a great tool! Everything works fine but I need to transpile the typescript code manually (via npx tsc) every time I edit the code... that's a bit annoying. If I don't do that, the test will run on the old transpilation. There is a way to run something like npx tsc before a test run? or am I missing a configuration somewhere? Thank you

hbenl commented 3 years ago

You should use a watcher, that will transpile each change as soon as you save it (and will be a lot faster than starting tsc and transpiling all sources every time). It's available by default as a task in VSCode: go to the Command palette and select "Tasks: Run Task" -> "typescript" -> "tsc: watch".

rallets commented 3 years ago

So there is no configuration (kind of trampoline) available in the adapter? is the watcher the only option? (so I can avoid that extra manual step)

hbenl commented 3 years ago

No, the adapter currently doesn't have such an option. If you want to avoid the extra manual step, you can configure the watcher to be run automatically (see here, in fact I use such a watcher task for this extension). Alternatively you can run your tests using ts-node (e.g. by adding "require": "ts-node/register/transpile-only" to .mocharc.json), then your sources will be compiled on-the-fly every time you run your tests (with the obvious performance hit).