Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix: check if module.paths really exists (#4194); closes #2505

Emanuele8b6a76c8dc64
diff --git a/lib/cli/cli.js b/lib/cli/cli.js
index dee8e70d..af0e7841 100755
--- a/lib/cli/cli.js
+++ b/lib/cli/cli.js
@@ -30,7 +30,9 @@ const {repository, homepage, version, gitter} = require('../../package.json');
exports.main = (argv = process.argv.slice(2)) => {
debug('entered main with raw args', argv);
// ensure we can require() from current working directory
- module.paths.push(process.cwd(), path.resolve('node_modules'));
+ if (typeof module.paths !== 'undefined') {
+ module.paths.push(process.cwd(), path.resolve('node_modules'));
+ }
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
diff --git a/lib/mocha.js b/lib/mocha.js
index 40718d09..bc5462da 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -29,7 +29,7 @@ exports = module.exports = Mocha;
* To require local UIs and reporters when running in node.
*/
-if (!process.browser) {
+if (!process.browser && typeof module.paths !== 'undefined') {
var cwd = process.cwd();
module.paths.push(cwd, path.join(cwd, 'node_modules'));
}