-
-
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
Adding an existence test to files pass to mocha with --file flag (closes #4047) #4167
Conversation
fs.statSync(file).isFile()
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.
Thanks for this!
I agree that it's currently not a great user experience. However, attempting to check the file before trying to require
it is a lot of complexity. Can you change the code so, instead, there's a try/catch/rethrow around this line:
Line 324 in ac25cf7
suite.emit(EVENT_FILE_REQUIRE, require(file), file, self); |
@@ -270,6 +273,19 @@ exports.builder = yargs => | |||
} | |||
}); | |||
|
|||
if (argv.file) { | |||
const nonExistentFiles = argv.file.filter( | |||
file => !fs.existsSync(file) || !fs.statSync(file).isFile() |
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.
just because the file exists doesn't mean we have permission to stat
it. likewise, this will fail on symlinks.
as explained in #4047
Description of the Change
Adding an existence test to files pass to mocha with
--file
flagIf specify non-existed file with --file option, mocha throw exception.
instead of showing the stack trace
Benefits
more friendly an informative way to terminate the process .