Open manuth opened 1 year ago
In your project's root, create a file
base.json
This confuses me. Nothing in the .mocharc.json
references extending base.json
. So it makes sense that the values in base.json
wouldn't be used.
Was the repro meant to have .mocharc.json
look like this?
{
"extends": "./base.json",
"timeout": 10000
}
The PR makes sense at first glance, and I can reproduce the buggy behavior by adding in the missing "extends"
. But I just want to be sure. 🙂
👋 ping @manuth, is this still on your radar?
Prerequisites
faq
labelnode_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Currently,
mocha
will load default settings fromlib/mocharc.json
from this package and only after doing so process the configuration usingyargs
.This breaks
yargs
extends
mechanism as the values predefined in saidmocharc.json
file cannot be overridden.This means that following settings cannot be specified using the
extends
config:diff
package
reporter
slow
timeout
ui
I assume that arrays still do work as, to my understanding, yargs will concatenate arrays taken from
extends
configs.Steps to Reproduce
mocha
tests written using thetdd
uibase.json
with the following content:.mocharc.json
:tdd
tests by running themocha
commandExpected behavior:
mocha
should be able to execute this test as the setting"ui": "tdd"
is supposed to be inherited.Actual behavior: [What actually happens]
mocha
will instead show the following error message:Reproduces how often: 100%
Versions
mocha --version
andnode_modules/.bin/mocha --version
: 10.0.2node --version
: 20.0.0bash
, PowerShell,cmd
Your browser and version (if running browser tests):Any third-party Mocha-related modules (and their versions):Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version):Additional Information
Notice that default values from this package's
lib/mocharc.json
file are applied to the current config file during the execution ofimport("mocha/lib/cli/options").loadOptions()
in this piece of code:https://github.com/mochajs/mocha/blob/37deed262d4bc0788d32c66636495d10038ad398/lib/cli/options.js#L246
Only after invoking
loadOptions()
, theextends
setting is processed byyargs
:loadOptions()
is executed - in doing so, values fromlib/mocharc.json
are applied https://github.com/mochajs/mocha/blob/37deed262d4bc0788d32c66636495d10038ad398/lib/cli/cli.js#L47extends
are processed byyargs
: https://github.com/mochajs/mocha/blob/37deed262d4bc0788d32c66636495d10038ad398/lib/cli/cli.js#L77Related to this question: #3916 There is also a PR addressing this issue: #4407 Furthermore, I created a PR myself: #4980