Auto-detect mocha.opts?

Looks like WebStorm is able to pick-up the `test/mocha.opts` configuration file relative to where the mocha is installed.

But with my following folder structure seems WebStorm is not able to pick up the nearest `mocha.opts` config (e.g., if I'm running a test under client/test/**/*.test.js then it should auto pick up the client/test/mocha.opts, and similar for server tests) and will throw an error when I try to run any test via WebStorm (control + R in MacOS). Is there a way to config so or workaround this? 

.
├── client
│   ├── src
│   └── test
│   └── mocha.opts
├── server
│   ├── src
│   └── test
│   └── mocha.opts
└── package.json

I'm using WebStorm 2020.3 Build #WS-203.5981.135, built on November 28, 2020. 

0
4 comments

You can specify the path explicitly in your run configuration using --opts path/to/mocha.opts:

0
Avatar
Permanently deleted user

Yeah, but then you should manually do this when running every tests via Control+Shift+R, which would then become really annoying and not realistic to manually do this every time. 

If it's not on your radar it's fine. I'm planning to change the project structure to be like the following so it should work again. 

.
├── src
│   ├── client
│   └── server
├── test
│   ├── client
│   ├── server
│   └── mocha.opts
└── package.json

 

0

@Linesh

Run/Debug Configurations have defaults that will be applied to a new created configuration.

0
Avatar
Permanently deleted user

Andriy Bazanov

Thanks for the comment. Yeah it'll be better if we have such feature - however, in my case I need to switch between client/test/mocha.opts and server/test/mocha.opts which might still need another manual config if you're switching between client/ and server/ tests?

0

Please sign in to leave a comment.