mocha
mocha copied to clipboard
support granular configuration
Mocha v6 now has configuration file support.
Originally, I had hoped this system could work more like ESLint's, where e.g., .mocharc.json
files could exist in multiple directories and affect only the test files at, and "below", this directory level.
Given that we can't get this behavior for free (there's overhead and complexity involved), do people think it's useful? Do people use this in ESLint?
A counter-example is Mocha's own .eslintrc.yml
, which uses the overrides
property to change ESLint's behavior on a per-file or per-directory basis. This is another way of expressing the same thing as multiple ESLint config files, except using only a single config.
At minimum, greater control over which test files use which config settings would be a positive. Mocha's own tests could leverage such a feature. Maybe all we need to do is support something like overrides
for now...?
Are we planning to drop the word "simple" from project description?
Came here looking for exactly this! Right now my team runs our tests on our locals via IntelliJ. If a test needs the --delay
flag I need to tell whoever's running it to set a run configuration with that flag, rather than being able to just go "hey run this test".
Per-directory or even per-file (via filename matching) config files would be fantastic.
For our team, being able to override the default configuration per directory, or better yet per file, would be fantastic.
:+1: for at least a per directory override, like it was possible with mocha.opts
It could be done allowing .mocharc.js
in all directories, or reading an override
property in the main configuration like eslint does, eg :
"mocha": {
"recursive": true,
"reporter": "spec",
"overrides": [{
"files": "test/**/*.test.js",
"require": "@babel/register"
}, {
"files": "testBrowser/**/*.test.js",
"require": "./testBrowser/init.js",
"slow": 5000,
"timeout": 10000
}]
}
I kind of wish I had this for working with VSCode extensions for running Mocha tests (running specific tests via --grep is becoming my biggest hassle with Mocha, so extensions would be a lot more convenient for this. Though I guess I should try .only
). The two popular ones won't work for me because they only support one global mocha configuration for the entire project, but I'm running different mocha commands for unit tests, selenium tests, database integration tests, etc.
I do kind of wish the extensions would just let me configure my own command to launch mocha, since I'm running it via build tasks that ensure docker containers are running etc. That would be more ideal. But if nothing else, having per-directory mocha configs would make it more likely I could use one of those VSCode extensions.
Did anyone find a way to do this with the project as-is? I have a project that runs with something like:
-
test/backend/**
:mocha --require extra-config-file.js
-
test/frontend/**
:mocha
Similar to a comment above, this means I can't just tell people to run a test. We have a script as a workaround, but with integrating with something like Intellij, that doesn't seem possible. Would be great if there was a way to do it, or if anyone had any tricks on how they've been doing it.
Per #5027, we're trying to avoid big shakeups. This would be a pretty big one.
Amusingly, even ESLint is moving away from nested configurations! https://eslint.org/blog/2022/08/new-config-system-part-2/
Thanks for the discussion all! Closing as wontfix. 🤎