Opening this as a question as I'm not yet sure whether it's a bug or a user error 馃槃
The docs on extending configuration state:
Configurations can inherit from other modules using the extends keyword
However, I've been unable to get this to work and I haven't been able to find any Mocha-specific examples leveraging extends. I've tried using extends both with a relative path to a json file, as well as with a module as referenced in the yargs docs linked from the Mocha docs, and I also tried the various Mocha config file formats (js, yaml, json, etc.) to define the Mocha config with the extends keyword, all to no avail.
I created a really simple repo here that reproduces this behavior:
ui should be set to tdd via the extends reference in the .mocharc.yml file, but running an npm test results in a reference error ReferenceError: suite is not defined leading me to believe that extends is not working since the ui is still set to the default bdd
Any help would be greatly appreciated!
I don't know wether it works or not. Let's suppose it works, then:
loadOptions() is already done (=default values are set) when the config object with your extends is consumed. The config values have lower priority and your tdd is ignored.ui in .mocharc.ymlextensionThanks for the response @juergba!
try to delete the default value of ui in .mocharc.yml
I added a ui: null in .mocharc.yml, but still experienced the same error (UI is still being set to the default bdd)
try an array option which accumulates values like extension
I tried this too, but unsurprisingly still get the same error due to the ui config setting of tdd not being honored
The second test was planned in a different way. Just to see wether your config is found and read:
ui to value you need (tdd) - we are not testing this optionextension to nonsense value like xx - we are testing this optionextension value (probably js) in your extend config.Just to confirm, does the below accurately reflect what you'd like me to try?
.mocharc.yml
ui: 'tdd'
extension: [ 'xx' ]
extends: './test/mocha-config.json'
test/mocha-config.json
{
"extension": [ "js" ]
}
@calebcartwright yes, that would have been the test I had in mind. Thanks for your investigations.
I did some tests and my conclusion is: in some edge cases it works, but in general it does not work.
So yes, a bug.
extends is a Yargs feature, which in Mocha runs too late, when all CLI plus config options have been read and default values have been set. Furthermore it runs outside of the public loadOptions() function.extends should run earlier in Yargs-parser, which has a similar feature config.config <==> yargs-parser configextend object and configObjects (and default values)?
Most helpful comment
@calebcartwright yes, that would have been the test I had in mind. Thanks for your investigations.
I did some tests and my conclusion is: in some edge cases it works, but in general it does not work.
So yes, a bug.
extendsis a Yargs feature, which in Mocha runs too late, when all CLI plus config options have been read and default values have been set. Furthermore it runs outside of the publicloadOptions()function.extendsshould run earlier in Yargs-parser, which has a similar featureconfig.there could be a conflict: Mocha
config<==> yargs-parserconfigextendobject andconfigObjects(and default values)?