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

Print warning message for --opts argument #3352

Closed
wants to merge 5 commits into from
Closed

Print warning message for --opts argument #3352

wants to merge 5 commits into from

Conversation

benedikt-roth
Copy link

@benedikt-roth benedikt-roth commented Apr 25, 2018

When specified options file does not exist

(Tackling #2576)

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions.

Description of the Change

  • Check if specified options file exists
  • If it does not, print a warning message

Alternate Designs

Why should this be in core?

Benefits

Less headache when your options file is not being loaded.

Possible Drawbacks

Applicable issues

  • This is probably a breaking change since it triggers a non-zero exit of the application.

When specified options file does not exist
@jsf-clabot
Copy link

jsf-clabot commented Apr 25, 2018

CLA assistant check
All committers have signed the CLA.

@benedikt-roth benedikt-roth changed the title Print warning message (relating to #2576) Print warning message for --opts argument Apr 25, 2018
@plroebuck
Copy link
Contributor

Like the idea and most of the coding implementation. But issue #2576 was for it to throw any error and die, rather than print warning and continue with defaults... Depending on how/where it is run, quite possible no one would notice the warning.

/* bin/options.js#L33 - don't continue, die! */
var noSuchFileError = new Error(`no such options file: ${optsPath}`);
noSuchFileError.code = 'ENOENT';
throw noSuchFileError;

@plroebuck
Copy link
Contributor

plroebuck commented Apr 25, 2018

Migrated to #3354

@benedikt-roth
Copy link
Author

Went for the less invasive variant in the beginning, but I would also prefer to make the script fail.

The code was changed to throw an error instead of a warning in 2dbc42f.

Need some more feedback on this change. If it proves to be the way to go, I will add some tests.

@benedikt-roth
Copy link
Author

I agree on that value assignment (2). Fixed it in f5cd0b5.

About the use of the env variable in general - It was introduced to fix #1980. Its purpose is not to try to process the options twice - once from the mocha wrapper and a second time from internal _mocha binary.

It looks like it was a quick fix and there might be a nicer way than to store it in a global env variable. Fixing that is the scope of a separate PR. I want to keep the changes rather small here.

@outsideris outsideris added the area: usability concerning user experience or interface label Apr 26, 2018
@plroebuck
Copy link
Contributor

Benedikt, was not trying to imply my post-review notes were to be part of your issue changes. 1) and 3) probably should have another issue opened. My apologies if that was unclear due to my adding those notes.

@benedikt-roth
Copy link
Author

It's all right, @plroebuck. It is good to talk about it since we are already here 🙂

Copy link
Member

@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! I have some comments was hoping you could address.

This is a breaking change, but it's a good one.

@@ -44,5 +52,5 @@ function getOptions() {
// ignore
}

process.env.LOADED_MOCHA_OPTS = true;
process.env.LOADED_MOCHA_OPTS = 'true';
Copy link
Member

@boneskull boneskull Apr 27, 2018

Choose a reason for hiding this comment

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

please just change this to 1 for simplicity

OK, so, to be clear, this is good enough the way it is. It should be 1, but apparently some odd projects are depending on this for one reason or another, and 'true' isn't so painful that this needs changing. If this is causing other issues in Mocha, or creates otherwise significant technical debt, we're free to modify or remove it as we see fit.

Projects should not be depending on this variable, and should certainly not be depending on its value to be any particular thing other than set or unset.

Copy link
Contributor

@plroebuck plroebuck Apr 28, 2018

Choose a reason for hiding this comment

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

Value needs to be 'true' to prevent breaking other npm packages unnecessarily.

Copy link
Member

Choose a reason for hiding this comment

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

What packages are using this? This is not documented and is not a "public" API (or an API at all, really).

Copy link
Author

Choose a reason for hiding this comment

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

I agree with @boneskull. LOADED_MOCHA_OPTS is intended for internal use only.
(Whereas this is not a good use case for an environment variable.)

process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];
const optPathSpecified = process.argv.indexOf('--opts') > -1;
Copy link
Member

Choose a reason for hiding this comment

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

this is nitpicky but can you please save the index? DRY and all that

const optsIndex = process.argv.indexOf('--opts');
const optsPathSpecified = optsIndex !== -1; // it will never be 0, so..
const optsPath = optsPathSpecified
  ? process.argv[optsIndex + 1]
  : 'test/mocha.opts';

? process.argv[process.argv.indexOf('--opts') + 1]
: 'test/mocha.opts';

if (optPathSpecified && !fs.existsSync(optsPath)) {
Copy link
Member

Choose a reason for hiding this comment

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

It's better to just do it and recover instead of make this extra check.

So on L52 where we're catching the err, inspect it for err.code === 'ENOENT', then you can throw with your noSuchFileError, otherwise just rethrow.

Copy link
Member

Choose a reason for hiding this comment

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

(in other words, avoid fs.existsSync)

@boneskull boneskull added the semver-major implementation requires increase of "major" version number; "breaking changes" label Apr 27, 2018
@boneskull boneskull force-pushed the master branch 2 times, most recently from 4547268 to 7613521 Compare May 4, 2018 16:47
@benedikt-roth
Copy link
Author

benedikt-roth commented May 5, 2018 via email

@benedikt-roth
Copy link
Author

Closing this one in favour of #3381.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: usability concerning user experience or interface semver-major implementation requires increase of "major" version number; "breaking changes"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants