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: log MODULE_NOT_FOUND when the karma.conf.js does not exist #1145

Merged
merged 6 commits into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function setUserKarmaConfigFile(config: Config, log: Logger) {
userConfig(config);
config.configFile = configFileName; // override config to ensure karma is as user-like as possible
} catch (error) {
log.error(`Could not read karma configuration from ${globalSettings.karmaConfigFile}.`, error);
if (error.code === 'MODULE_NOT_FOUND') {
log.error(`Unable to find karma config at "${globalSettings.karmaConfigFile}" (tried to load from ${configFileName}). Please check your stryker config. You might need to make sure the file is included in the sandbox directory.`);
} else {
log.error(`Could not read karma configuration from ${globalSettings.karmaConfigFile}.`, error);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ describe('stryker-karma.conf.js', () => {
expect(requireModuleStub).calledWith(path.resolve('foobar.conf.js'));
});

it('should log an error if the karma config file could not be found', () => {
// Arrange
const actualError = new Error('Module not found') as NodeJS.ErrnoException;
actualError.code = 'MODULE_NOT_FOUND';
requireModuleStub.throws(actualError);
const expectedKarmaConfigFile = 'foobar.conf.js';
sut.setGlobals({ karmaConfigFile: expectedKarmaConfigFile });

// Act
sut(config);

// Assert
expect(logMock.error).calledWithMatch(`Unable to find karma config at "foobar.conf.js" (tried to load from ${path.resolve(expectedKarmaConfigFile)})`);
expect(requireModuleStub).calledWith(path.resolve(expectedKarmaConfigFile));
});

it('should set user configuration from custom karma config', () => {
sut.setGlobals({ karmaConfig: { basePath: 'foobar' } });
sut(config);
Expand Down