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

3363: Throw error if unable to parse Mocha options file #3376

Closed
wants to merge 4 commits into from

Conversation

plroebuck
Copy link
Contributor

@plroebuck plroebuck commented May 4, 2018

Description of the Change

Code now throws an error for any problems loading the Mocha options file (except for nonexistent default "test/mocha.opts").

Builds off of previous discussions and work done in PR #2716 and PR #3352 .

Why should this be in core?

Silently ignoring problems loading this file is just wrong.

Benefits

Users will now be told if the file failed to load.

Possible Drawbacks

Users with invalid Mocha options files (or permissions problems, etc.) will need to correct the problem.

Applicable issues

Fixes #3363
Fixes #2576
(server-major) [since Mocha could throw an error when it didn't previously]

Code now throws an error for any problems (except nonexistent default "test/mocha.opts").

Fixes mochajs#3363
@coveralls
Copy link

coveralls commented May 4, 2018

Coverage Status

Coverage decreased (-0.01%) to 89.995% when pulling 4d0aaa1 on plroebuck:issues/3363 into 7613521 on mochajs:master.

@plroebuck
Copy link
Contributor Author

BTW, anyone run across this ChromeHeadless problem before? Same code ran file for all test jobs except this last one. Restarting made no difference. MochaJS PR run afterwards was fine.

Copy link
Contributor

@outsideris outsideris left a comment

Choose a reason for hiding this comment

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

LGTM

@outsideris
Copy link
Contributor

@plroebuck You didn't set saucelab in your travisci, seePlease set SAUCE_USERNAME and SAUCE_ACCESS_KEY env variables.

@outsideris outsideris added the type: bug a defect, confirmed by a maintainer label May 5, 2018
Added information on file content, noting support for comment/blank lines.
@plroebuck
Copy link
Contributor Author

@outsideris, add "server-major" tag, pls!

@outsideris outsideris added the semver-major implementation requires increase of "major" version number; "breaking changes" label May 6, 2018
@plroebuck
Copy link
Contributor Author

@boneskull ping

@boneskull boneskull added area: usability concerning user experience or interface and removed type: bug a defect, confirmed by a maintainer labels May 8, 2018
@boneskull
Copy link
Contributor

will review some stuff tomorrow

Copy link
Contributor

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

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

why is this change semver major?

@outsideris
Copy link
Contributor

@Bamieh I think this is a breaking change because users will get the errors when there is no opts file. Before this change, users don't care about the existence of the opts file.

@Bamieh
Copy link
Contributor

Bamieh commented May 8, 2018

@outsideris makes sense, but looking at the code, it will only throw if there is an error in the existing file. if it does not exist, no errors will be throws. So i have a feeling that this is more of a bug fix rather than a breaking change.

  • Users with no opt file will not be affected.
  • Users with working opt files will not be affected.
  • Users with broken opt files will have a new exception thrown that did not throw in the past.

Do you think there are people running mocha with a broken opt file? I believe its not that case because mocha would not be running as they expect anyways.

@plroebuck
Copy link
Contributor Author

plroebuck commented May 8, 2018

Not exactly, @outsideris... It's a breaking change because an Error could now occur where it does not in the current version. Even though the existing code is broken (due to masking), I consider it major since it might disrupt the CI process by causing run failures.

Mocha would now throw when user-specified --opt options file doesn't exist, cannot be read, or if a parsing error occurs due to its content. The default "test/mocha.opts" not existing will not trigger an error, but any other problem will.

@plroebuck
Copy link
Contributor Author

plroebuck commented May 8, 2018

| Do you think there are people running mocha with a broken opt file? I believe its not that case
| because mocha would not be running as they expect anyways.

Point being that they may not even know it's broken yet...
#2576

"confirmed-bug" label was correct.

@outsideris
Copy link
Contributor

If so, it seems semver-minor, not semver-major like what @Bamieh said.

@plroebuck
Copy link
Contributor Author

it's server-major if upgrading can break something.
https://blog.greenkeeper.io/introduction-to-semver-d272990c44f2

@boneskull
Copy link
Contributor

boneskull commented May 8, 2018

This would be a bug if Mocha had intended to throw an error upon an invalid opts file, but failed to do so correctly.

Since Mocha's current behavior is intended (which is to say, doing nothing) this isn't a bug fix. But it is a breaking change.

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.

It should be possible to write an integration test for this. You can create a dummy invalid mocha.opts file somewhere under test/integration/fixtures/ and use the runMocha helper with args --opts /path/to/bad/mocha.opts, and assert the output contains an error.

This will also appease Coveralls.

Added tests for `--opts` as none previously existed. Added "do nothing" fixture test. Minor change
to helper routine so that it used `path.join()` properly.
@plroebuck
Copy link
Contributor Author

Had problems getting this branch updated post-UnexpectedJS. Opening new PR instead.

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.

5 participants