-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correct precedence of configuration extends and defaults #4980
base: main
Are you sure you want to change the base?
Conversation
This PR hasn't had any recent activity, and I'm labeling it |
Just pinging to have the |
Note: #4407 also touches this area. We should review them together in case one is a dup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good and reasonable, nice! 🔥
Marking as requesting changes just so we can chat about the two possible implementations a bit.
Marking as |
👋 just checking in @manuth, anything I can help with? |
Alright, so I made a little digging. As described in issue #4979, the underlying issue that causes Mocha to ignore certain settings from In order to fix this, My solution was to run Lines 81 to 83 in f131e9a
The solution proposed by @mf-pherlihy is to process the config using Lines 130 to 142 in f07d427
ConclusionOf course, I might be biased as former solution is written by me while latter isn't. Furthermore, it uses However, there are more... Things to ConsiderI have just noticed that RC config files aren't the only place where the I'd recommend adding a function (like One more thing is that currently, because Late Yargs ProcessingMocha processing the configuration using Let's imagine a config file: {
"extends": "./base.json",
"timeout": 1000
} And base config: { "ui": "tdd" } First, at this line, Mocha will apply the global defaults to the config: Line 27 in 75dcf8c
or, when called through _mocha :Line 51 in 75dcf8c
Making the runtime-configuration at this point look like this: Runtime-Config After {
"_": [],
"config": false,
"package": false,
"extends": "./base.json",
"timeout": 1000,
"diff": true,
"extension": [
"js",
"cjs",
"mjs"
],
"reporter": "spec",
"slow": 75,
"ui": "bdd",
"watch-ignore": [
"node_modules",
".git"
]
}
After that, Line 81 in 75dcf8c
You will notice, that the configuration At time of writing, the |
So... uh... looks like I did a little oupsie in this PR: I fixed this in commit a41006d by adding Furthermore, as discussed in my previous comment, I added a new function Now, I'm ready for a review, I guess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 Whoohoo! I love how the changes in lib/cli/options.js
are super straightforward now - just one extracted function for the two loading places.
I tried this out in the https://github.com/mochajs/mocha-examples packages that use a mocha config file and nothing was broken (that wasn't already broken...). So that's great.
I also think that because this is a breaking change for the next behavior-changing major, we'll have an alpha/beta/rc out in public for folks to try it out with. So I say 🚀 great! The only blocker now is waiting for us to get to being able to working on that major.
Marking as approved, with the notes that:
- Ideally if someone else in @mochajs/maintenance-crew has time, they should review too
- We're blocked from merging until the work on the next major gets going
Thanks @manuth! 🙌
lib/cli/options.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yargs
must run before Mocha's global defaults are applied.
ACK, that seems reasonable to me. As I understand it: Mocha-specific global defaults are meant to tack on if nothing is specified in Yargs-land. Having Yargs-land finish before Mocha-land starts seems right.
Co-authored-by: Josh Goldberg ✨ <[email protected]>
Awesome! Thank you so much for reviewing - and also thanks for the feedback, I really appreciate it 😄 |
Requirements
Description of the Change
As described in issue #4979, due to
mocha
first loading its default settings and after doing so processing the arguments usingargs
, there are some settings which cannot be inherited by specifying anextends
file:mocha/lib/cli/options.js
Line 246 in 37deed2
mocha/lib/cli/cli.js
Line 77 in 37deed2
Changes made in this PR processes configuration files using
yargs
right after they have been parsed. Thus, the order of events is now the following:yargs
package.json
settings are loadedargv
get mergedmocha
s default values (fromlib/mocharc.json
) get appliedAlternate Designs
Configuration files could be processed right before
mocha
s defaults get applied. However, the context of the file path would get lost thus causing relativeextends
paths to possibly fail.Applying
mocha
s default values could be removed from here:https://github.com/mochajs/mocha/blob/37deed262d4bc0788d32c66636495d10038ad398/lib/cli
And instead be done somewhere around here (after
yargs
has been executed):mocha/lib/cli/cli.js
Line 47 in 37deed2
Why should this be in core?
Currently, the inheritance will not work for a number of settings while other settings do. This might cause confusion and unexpected results. Thus, I'd recommend to have this change in core.
Benefits
All settings will be able to be inherited while
mocha
s defaults still get applied if necessary.Possible Drawbacks
None that I have heard of.
If people already used
extends
for their own project, there is a chance that they relied on the inheritance ofui
to not work, so there is a small possibility they will have to perform a one-time change to their config file.Applicable issues
Enter any applicable Issues here.
Mocha follows semantic versioning: http://semver.org
Is this a breaking change (major release)?Is it an enhancement (minor release)? (Maybe?)
Is it a bug fix, or does it not impact production code (patch release)?
Or probably a minor as there is a small possibility people have to adjust their configuration if they used
extends
beforeFixes #4979
Fixes #3916
Co-authored-by: Pat Herlihy @mf-pherlihy