-
-
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
Create Module not found error #4826
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,14 @@ var constants = { | |
* @constant | ||
* @default | ||
*/ | ||
UNPARSABLE_FILE: 'ERR_MOCHA_UNPARSABLE_FILE' | ||
UNPARSABLE_FILE: 'ERR_MOCHA_UNPARSABLE_FILE', | ||
|
||
/** | ||
* File attempts to import non-existent module | ||
* @constant | ||
* @default | ||
*/ | ||
MODULE_NOT_FOUND: 'ERR_MOCHA_MODULE_NOT_FOUND' | ||
}; | ||
|
||
/** | ||
|
@@ -516,6 +523,25 @@ function createUnparsableFileError(message, filename) { | |
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object to be thrown when file attempts to import module that does not exist. | ||
* @public | ||
* @static | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} importerFilename - File name of importing module | ||
* @param {string} importedFilename - File name of imported module | ||
* @returns {Error} Error with code {@link constants.MODULE_NOT_FOUND} | ||
*/ | ||
function createModuleNotFoundError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need a new Mocha error code, we can't wrap each and every Node error in a new Mocha error object. We just have to rethrow Node's error somehow or include Node's error message in Mocha's |
||
message, | ||
importerFilename, | ||
importedFilename | ||
) { | ||
var err = new Error(message); | ||
err.code = constants.MODULE_NOT_FOUND; | ||
return err; | ||
} | ||
|
||
/** | ||
* Returns `true` if an error came out of Mocha. | ||
* _Can suffer from false negatives, but not false positives._ | ||
|
@@ -547,6 +573,7 @@ module.exports = { | |
createNoFilesMatchPatternError, | ||
createTimeoutError, | ||
createUnparsableFileError, | ||
createModuleNotFoundError, | ||
createUnsupportedError, | ||
deprecate, | ||
isMochaError, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
require('invalidImport.js'); | ||
// a comment | ||
module.exports = { | ||
require: ['foo', 'bar'], | ||
bail: true, | ||
reporter: 'dot', | ||
slow: 60 | ||
}; |
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.
It's not clear to me how you are going to distinguish
module not found
errors caused by invalid path (seeparsers
) and by invalid imports.