Skip to content

Commit 7313890

Browse files
Fix exception rethrow from js config file (#4702)
1 parent 3722201 commit 7313890

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/cli/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports.CONFIG_FILES = [
3131
];
3232

3333
const isModuleNotFoundError = err =>
34-
err.code !== 'MODULE_NOT_FOUND' ||
34+
err.code === 'MODULE_NOT_FOUND' ||
3535
err.message.indexOf('Cannot find module') !== -1;
3636

3737
/**

test/integration/config.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ describe('config', function() {
4747
expect(js, 'to equal', json);
4848
});
4949

50+
it('should rethrow error from absolute path configuration', function() {
51+
function _loadConfig() {
52+
loadConfig(path.join(configDir, 'mocharcWithThrowError.js'));
53+
}
54+
55+
expect(_loadConfig, 'to throw', {
56+
message: /Error from mocharcWithThrowError/
57+
});
58+
});
59+
60+
it('should rethrow error from cwd-relative path configuration', function() {
61+
var relConfigDir = configDir.substring(projRootDir.length + 1);
62+
63+
function _loadConfig() {
64+
loadConfig(path.join('.', relConfigDir, 'mocharcWithThrowError.js'));
65+
}
66+
67+
expect(_loadConfig, 'to throw', {
68+
message: /Error from mocharcWithThrowError/
69+
});
70+
});
71+
5072
// In other words, path does not begin with '/', './', or '../'
5173
describe('when path is neither absolute or relative', function() {
5274
var nodeModulesDir = path.join(projRootDir, 'node_modules');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
throw new Error("Error from mocharcWithThrowError");
4+
5+
// a comment
6+
module.exports = {
7+
require: ['foo', 'bar'],
8+
bail: true,
9+
reporter: 'dot',
10+
slow: 60
11+
};

0 commit comments

Comments
 (0)