diff --git a/lib/cli/config.js b/lib/cli/config.js index b7510d7deb..10f16d8aa3 100644 --- a/lib/cli/config.js +++ b/lib/cli/config.js @@ -31,7 +31,7 @@ exports.CONFIG_FILES = [ ]; const isModuleNotFoundError = err => - err.code !== 'MODULE_NOT_FOUND' || + err.code === 'MODULE_NOT_FOUND' || err.message.indexOf('Cannot find module') !== -1; /** diff --git a/test/integration/config.spec.js b/test/integration/config.spec.js index 52fa886220..4c65f76c24 100644 --- a/test/integration/config.spec.js +++ b/test/integration/config.spec.js @@ -47,6 +47,28 @@ describe('config', function() { expect(js, 'to equal', json); }); + it('should rethrow error from absolute path configuration', function() { + function _loadConfig() { + loadConfig(path.join(configDir, 'mocharcWithThrowError.js')); + } + + expect(_loadConfig, 'to throw', { + message: /Error from mocharcWithThrowError/ + }); + }); + + it('should rethrow error from cwd-relative path configuration', function() { + var relConfigDir = configDir.substring(projRootDir.length + 1); + + function _loadConfig() { + loadConfig(path.join('.', relConfigDir, 'mocharcWithThrowError.js')); + } + + expect(_loadConfig, 'to throw', { + message: /Error from mocharcWithThrowError/ + }); + }); + // In other words, path does not begin with '/', './', or '../' describe('when path is neither absolute or relative', function() { var nodeModulesDir = path.join(projRootDir, 'node_modules'); diff --git a/test/integration/fixtures/config/mocharcWithThrowError.js b/test/integration/fixtures/config/mocharcWithThrowError.js new file mode 100644 index 0000000000..f88872027e --- /dev/null +++ b/test/integration/fixtures/config/mocharcWithThrowError.js @@ -0,0 +1,11 @@ +'use strict'; + +throw new Error("Error from mocharcWithThrowError"); + +// a comment +module.exports = { + require: ['foo', 'bar'], + bail: true, + reporter: 'dot', + slow: 60 +};