piotrwitek / ts-mocha

Mocha thin wrapper that allows running TypeScript tests with TypeScript runtime (ts-node) to get rid of compilation complexity
MIT License
190 stars 25 forks source link

ts-mocha --watch is not re-running test cases on file changes #69

Closed kfern closed 2 years ago

kfern commented 2 years ago

Hi!

I'm using ts_mocha 8 but it's not re-running test cases on file changes.

My mocha command is

ts-mocha \"test/**/*.ts\" --recursive --exit

If I add watch and watch-extensions options the tests are run once and not rerun when the tests or source code is modified

ts-mocha \"test/**/*.ts\" --watch --watch-extensions ts
...
[mocha] waiting for changes...

It's a bug? Any idea how can I solve it?

SO: Ubuntu 21.04 node -v: v12.22.1

Related dependencies: "@types/mocha": "^9.0.0" "mocha": "^8.2.1" "ts-mocha": "^8.0.0"

ahmednaser94 commented 2 years ago

Same problem on windows 11 Related dependencies: "ts-mocha": "^8.0.0", "@types/mocha": "^9.0.0", "mocha": "^8.4.0",

andrewminer commented 2 years ago

Same problem on MacOS Monterey:

"mocha": "^9.2.2",
"ts-mocha": "^9.0.2",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.14.1",
"typescript": "^4.6.2",
andrewminer commented 2 years ago

This is actually a problem with the README.md in this repository. ts-mocha doesn't actually know anything about watching files... it just passes any arguments it doesn't recognize along to Mocha. The instructions here reference the --watch-extensions argument, which has been replaced with --watch-files, which expects a glob. Therefore, the example should be:

ts-mocha --paths -p src/ 'src/**/*.spec.ts' -w --watch-files 'src/**/*.ts'
divmgl commented 2 years ago

https://github.com/piotrwitek/ts-mocha/issues/69#issuecomment-1077739875

Wow, this is huge. THANK YOU. I'd even open a PR against the README.md to fix that.

kfern commented 2 years ago

For others with the same issue:

-p: relative or absolute path to a tsconfig.json (default: "./tsconfig.json")

Example with test folder, watching all ts files: ts-mocha test/**/*.spec.ts -w --watch-files '**/*.ts'

piotrwitek commented 2 years ago

Could you please open a PR with an update to the readme with your example snippet? I'll merge. Thanks

kfern commented 2 years ago

@piotrwitek Done!

piotrwitek commented 2 years ago

Merged, thanks a lot 👍