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

Handled exception of--file option with non-existed file(#4047) #4056

Closed
wants to merge 4 commits into from

Conversation

leehwarang
Copy link

Description of the Change

In handleRequires, a function that handles exceptions when invoking a module that does not exist with the --require option. However, function handleRequires can also be used to load non-existent files with the --file option.

So I added this function to be called when I loaded the file using --file option. And I modified the annotation of this function.

./bin/mocha --require non-exist-module

module

./bin/mocha --file non-exist-file

file

Benefits

When user import a non-existent file or module, command line can show the user the same error message and format.

- Function `handleRequires` is used both when commanded using --require and --file.
@outsideris
Copy link
Member

ref: #4047

@outsideris outsideris added type: bug a defect, confirmed by a maintainer semver-patch implementation requires increase of "patch" version number; "bug fixes" area: usability concerning user experience or interface labels Oct 13, 2019
@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 92.757% when pulling d368df5 on leehwarang:issue/4047 into 3633a90 on mochajs:master.

exports.handleFiles = (files = []) => {
files.forEach(file => {
if (!fs.existsSync(file, {cwd})) {
throw Error(`Cannot find module '${file}'`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test for this please.

@@ -79,6 +79,7 @@ exports.list = str =>
* @param {string[]} requires - Modules to require
* @private
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesnt need the space (same below)

@JoshuaKGoldberg
Copy link
Member

🤖 Closing out old PRs to keep the queue small. Please yell at me if you'd like to keep working on this. Cheers!

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-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.

None yet

5 participants