Run mocha reporter programatically
I want to use the test functionality in webstorm, but the only way to use it is trough a mocha 'Run/Debug Configuration'.
The problem is that I have a `runner.ts` file and running mocha programatically using mocha.run() (https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically) and I can't run my tests in that way and have WebStorm tests and coverage funcionality.
I already tried using web storm reporter 'mochaIntellijReporter.js' but don't have a way to integrate that with the IDE
Is it possible to use webstorm tests functionality in that case?
请先登录再写评论。
No, you need running mocha through the Mocha test runner to be able to use Mocha run configuration; with custom test runners, you can only run Mocha tests in IDE using Node.js run configuration
The functionality used by the IDE "only" listens to the output of the reporter `mochaIntellijReporter` that comes with webstorm `webstorm/90/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js`...
It would be great if we could call that listener on a *Node.js* configuration or something..
Does it make sense what I'm saying?
Thanks
Adding a listener on Node.js run/debug configuration that will switch to Mocha run/debug configuration is not supported and unlikely it will be done.
But you can create your custom compatible adapter for Mocha. Here is an example of such an adapter (`my-project/my-mocha-runner`) and mocha is installed as `my-project/node_modules/mocha`:
Then, specify `/path/to/my-project/my-mocha-runner` as "Mocha package" in a Mocha run/debug configuration and run/debug it.
That worked for the tests! :D Thanks!
Only one final question, when I try to run the "coverage" action of this configuration, I get:
`Error: spawn /<path_to_project>/tests/bin/_mocha EACCES`
Is there a way to get it to work without using sudo?
Yeah, `my-project/my-mocha-runner/bin/_mocha` needs execution permissions to run with coverage. For example, `chmod +x my-mocha-runner/bin/_mocha` for Linux.