Combine mocha, Typescript (and watch)

this command watch typescript test changes and fire them (ts-node should be installed):

"scripts": {
"watch": "mocha -r ts-node/register test/*Test.ts  --watch --watch-extensions ts"
}

I wrote ts-node after running into a similar use-case (https://github.com/TypeStrong/ts-node). I needed to run tests with different test runners and compiling to a different directory doesn't cut it because I also like inlining the test fixtures. It's been expanded into feature complete node runtime for TypeScript (including a CLI with a cool little .type command feature). There's an example in the README for executing it with Mocha.

It's all in-memory right now, but eventually it will be expanded with additional flags to make it reasonable for production usage (E.g. no runtime overhead, just compilation startup). Let me know how it goes for you!


For me I had to add a prefix like **/

mocha -r ts-node/register "test/**/*.ts" --watch --watch-files **/*

And for multiple specific folders/files:

mocha -r ts-node/register "test/**/*.ts" --watch --watch-files src/**/*,test/**/*