mocha-sidebar icon indicating copy to clipboard operation
mocha-sidebar copied to clipboard

mocha.opts file not respected by mocha

Open RikkiGibson opened this issue 8 years ago • 16 comments

I use a mocha.opts file to specify the settings to pass to mocha. Since it's in the conventional location ./test/mocha.opts in my project, mocha is able to pick it up automatically when I just run mocha on the command line.

mocha-sidebar didn't pick this up by default, and didn't seem to respect the mocha.opts settings when I added the following config setting (assuming the items in this object basically just get passed as arguments to mocha):

{
  "mocha.options": {
    "opts": "./test/mocha.opts"
  }
}

It would be nice to not have to keep my settings in sync across ./vscode/settings.json and mocha.opts. Any idea how I could get mocha-sidebar to pick up this config when running mocha?

RikkiGibson avatar Mar 26 '18 01:03 RikkiGibson

I Will try to parse it coz there is now API to pass it directly when running mocha from code

maty21 avatar Jul 24 '18 19:07 maty21

Any update on this?

jumpdartmark avatar Dec 04 '18 15:12 jumpdartmark

Note that mocha v6 now supports, in addition to the legacy "/test/mocha.opts" file, a "/.mocharc.js", a "/.mocharc.json", a "/.mocharc.yaml", and allows specifying settings in package.json. Details are here. (The .js one is especially nice, because you can put comments in it. 😃)

jwalton avatar Apr 03 '19 14:04 jwalton

Note that mocha v6 now supports, in addition to the legacy "/test/mocha.opts" file, a "/.mocharc.js", a "/.mocharc.json", a "/.mocharc.yaml", and allows specifying settings in package.json. Details are here. (The .js one is especially nice, because you can put comments in it. 😃)

@jwalton I tried this, but the sidebar is still not the new config file. Did you actually get it to work?

mistersimon avatar Apr 12 '19 05:04 mistersimon

No, I don't think it supports any of these. :/

jwalton avatar Apr 12 '19 17:04 jwalton

I'm currently working on major refactoring after this it will be much easier to add new features

On Fri, Apr 12, 2019, 8:10 PM Jason Walton [email protected] wrote:

No, I don't think it supports any of these. :/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/maty21/mocha-sidebar/issues/84#issuecomment-482651420, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_nubv2xihQRIMyVki6B-nDaN0m9y1Yks5vgL3qgaJpZM4S6agZ .

maty21 avatar Apr 12 '19 17:04 maty21

If you're interested in some help, I'd be happy to submit a PR for reading mocha config after your major refactor and the unrelated major refactor I'm working on right now on my project. ;)

jwalton avatar Apr 12 '19 17:04 jwalton

Seems like it is still not working for me. Any update on this?

grobee avatar Jul 24 '19 09:07 grobee

https://mochajs.org/api/module-lib_cli_options.html#.loadOptions <- This might be of interest?

gertsonderby avatar Aug 07 '19 17:08 gertsonderby

I hope the configs can be used soon then i can use this extension too :D

DaniGTA avatar Aug 16 '19 21:08 DaniGTA

It would be great to check for a .mocharc file in the sidebar directory.

carlo-quinonez avatar Jan 09 '20 20:01 carlo-quinonez

I was able to get it working by changing the plugin settings to support typescript and a different UI view the mocha options settings.

carlo-quinonez avatar Jan 10 '20 23:01 carlo-quinonez

Hi guys. I found the solution for .mocharc.js file support. It looks like a workaround but works for me. Open your settings.json file and add .mocharc.js file in mocha.requires section

"mocha.requires": [
        "ts-node/register",
        "tsconfig-paths/register",
        ".mocharc.js"
    ],

image image

vitalics avatar May 26 '21 12:05 vitalics

@vitalics - thx for the tip but it didn't work for me :-( i have a .mocharc.js file in the root of my project and pointed mocha.requires at it but i still get the dreaded No Mocha options are configured. You can set it under File > Preferences > Workspace Settings. message ... awesome extension but support for mocha options file really should be added

mverkerk-godaddy avatar Aug 23 '21 09:08 mverkerk-godaddy

More than 1 year without update. Is this problem still being tracked?

ricardovsilva avatar Sep 28 '22 01:09 ricardovsilva

I switched to: https://github.com/hbenl/vscode-mocha-test-adapter

Install with:

$ code --install-extension hbenl.vscode-mocha-test-adapter

Then for your typescript projects, in PROJECTROOT/.vscode/settings.json:

{
  "mochaExplorer.files": "**/*.spec.ts",
  "mochaExplorer.require": "ts-node/register/transpile-only",
}

(Replace the "**/*.spect.ts" with an appropriate wildcard - these are the files that will be watched. Replace ts-node if you're not using ts-node.)

jwalton avatar Sep 28 '22 20:09 jwalton