Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug: Configurations don't seem to support 'extends' #3916

Open
calebcartwright opened this issue May 14, 2019 · 7 comments
Open

馃悰 Bug: Configurations don't seem to support 'extends' #3916

calebcartwright opened this issue May 14, 2019 · 7 comments
Labels
semver-major implementation requires increase of "major" version number; "breaking changes" status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@calebcartwright
Copy link

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!

@calebcartwright calebcartwright added the type: question support question label May 14, 2019
@juergba
Copy link
Member

juergba commented May 16, 2019

I don't know wether it works or not. Let's suppose it works, then:

  • the main parsing in 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.
  • try to delete the default value of ui in .mocharc.yml
  • try an array option which accumulates values like extension

@calebcartwright
Copy link
Author

Thanks 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

@juergba
Copy link
Member

juergba commented May 18, 2019

The second test was planned in a different way. Just to see wether your config is found and read:

  • set default ui to value you need (tdd) - we are not testing this option
  • set default extension to nonsense value like xx - we are testing this option
  • set correct extension value (probably js) in your extend config.

@calebcartwright
Copy link
Author

calebcartwright commented May 21, 2019

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" ]
}

@juergba juergba added type: bug a defect, confirmed by a maintainer and removed type: question support question labels May 21, 2019
@juergba
Copy link
Member

juergba commented May 21, 2019

@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.
    there could be a conflict: Mocha config <==> yargs-parser config
  • which priority between extend object and configObjects (and default values)?

@mf-pherlihy
Copy link

#4407

@JoshuaKGoldberg JoshuaKGoldberg changed the title Does the extending configuration feature work? 馃悰 Bug: Configurations don't seem to support 'extends' Dec 27, 2023
@JoshuaKGoldberg
Copy link
Member

Marking as semver-major because some projects might accidentally be relying on the current, arguably broken behavior.

@JoshuaKGoldberg JoshuaKGoldberg added the semver-major implementation requires increase of "major" version number; "breaking changes" label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major implementation requires increase of "major" version number; "breaking changes" status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants