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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 22 additions & 0 deletions
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');
Lines changed: 11 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy