Skip to content

Commit

Permalink
Fix exception rethrow from js config file (#4702)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-golovan committed Jul 25, 2021
1 parent 3722201 commit 7313890
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cli/config.js
Expand Up @@ -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;

/**
Expand Down
22 changes: 22 additions & 0 deletions test/integration/config.spec.js
Expand Up @@ -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');
Expand Down
11 changes: 11 additions & 0 deletions 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
};

0 comments on commit 7313890

Please sign in to comment.