Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error rethrow from cwd-relative path js config file #4702

Merged
merged 1 commit into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cli/config.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ describe('config', function() {
expect(js, 'to equal', json);
});

it('should rethrow error from absolute path configuration', function() {
juergba marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -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
};