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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No double reloading defaults, fixes #3808 #3820

Closed
wants to merge 1 commit into from

Conversation

dedene
Copy link

@dedene dedene commented Mar 9, 2019

Description of the Change

As the mocha defaults were merged early on(https://github.com/mochajs/mocha/blob/master/lib/cli/options.js#L331), it prevented the yargs parser to properly fallback to its defaults configuration for each cli argument (which are coming from the same defaults (https://github.com/mochajs/mocha/blob/master/lib/cli/run.js#L26). With this fix 'js' is no longer always included in the list of extensions.

Why should this be in core?

This fixes issue #3808

Benefits

Allow mocha to properly run i.e. in Typescript based projects.

@jsf-clabot
Copy link

jsf-clabot commented Mar 9, 2019

CLA assistant check
All committers have signed the CLA.

@dedene
Copy link
Author

dedene commented Mar 9, 2019

The test for loadOptions fail on the part when no options are given or missing and they should be filled in by the defaults. But isn't it so when no options are given, the defaults as configured in the yargs config will be taken..

const defaults = require('../mocharc');

which has the same effect?

@juergba
Copy link
Contributor

juergba commented Mar 11, 2019

I think the bug can be found here: lib/utils.js

extensions contains the correct CL-input, but does not use it within the function. jsis hard coded.

This is probably the reason:

--extension , --watch-extensions
Updated in v6.0.0. Previously --watch-extensions, but now expanded to affect general test file loading behavior. --watch-extensions is now an alias

Copy link
Contributor

@boneskull boneskull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Please revert this change, and see juergba's comment.

That code needs to be changed to use the contents of the extension option instead of .js.

@boneskull boneskull added semver-patch implementation requires increase of "patch" version number; "bug fixes" type: bug a defect, confirmed by a maintainer labels Mar 11, 2019
@juergba
Copy link
Contributor

juergba commented Mar 12, 2019

I think we have more than one bug here. Something is wrong with the parsing of the extension option as well.

extension is of yargs option type = "array[]". => "run-option-metadata.js"
The way we parse and coerce those "array[]" => "YARGS_PARSER_CONFIG" = {'combine-arrays': true}
This must be the reason why the default extension which is the last member in the access sequence, is added to the extension array.

@dedene You have to get rid of this default js somehow. You can't just delete mocharc as you did before. Probably you should delete the default js before parsing. After parsing you don't know anymore which soure file provided js.

@boneskull
Copy link
Contributor

extension is of yargs option type = "array[]". => "run-option-metadata.js"
The way we parse and coerce those "array[]" => "YARGS_PARSER_CONFIG" = {'combine-arrays': true}
This must be the reason why the default extension which is the last member in the > access sequence, is added to the extension array.

This is likely the reason. It's a regression, then. Essentially, I think we're going to need a special case that says "when merging the default configuration, if extension is defined and not the default value, do not merge the default value into the array."

@boneskull
Copy link
Contributor

We want "combine arrays" to work in all other cases (AFAIK!) except this one.

@boneskull
Copy link
Contributor

boneskull commented Mar 12, 2019

@dedene this is kind of hairy, and there's no easy way to make yargs-parser do what we want here--nor is it easy to explain exactly what it is we want to happen. If you don't want to continue with this PR, please let me know, and I'll pick it up.

@dedene
Copy link
Author

dedene commented Mar 12, 2019

@juergba @boneskull thanks for the feedback! I don't have much time this week, so feel free to take it over. Shall I close the PR or can you edit and continue on this PR?

@juergba
Copy link
Contributor

juergba commented Mar 13, 2019

@boneskull maybe you can use yargs "coerce" option.

When you do it before reducing the array to unique values, the logic is simple:
when "extension.length > 1" then delete one "js". If there is a second "js", it's one the user set intentionally and must not be deleted.

@boneskull
Copy link
Contributor

closed in lieu of #3834

@boneskull boneskull closed this Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants