Skip to content

Commit

Permalink
feat: Fail on launcher-, reporter-, or preprocessor-load errors.
Browse files Browse the repository at this point in the history
Fail out of karma if a launcher, reporter, or preprocessor fails to
load, after attempting to load each of them, and reporting errors for
each load error.

This is a WIP: I can't quite figure out where to place a final check on
whether any errors were caught while loading launchers, reporters, or
preprocessors. Any quick tip would be much appreciated!

Closes #855
  • Loading branch information
srawlins committed Nov 7, 2014
1 parent 578c340 commit 3e6900f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
7 changes: 4 additions & 3 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ var Launcher = function(emitter, injector) {
browser = injector.createChild([locals], ['launcher:' + name]).get('launcher:' + name);
} catch (e) {
if (e.message.indexOf('No provider for "launcher:' + name + '"') !== -1) {
log.warn('Can not load "%s", it is not registered!\n ' +
'Perhaps you are missing some plugin?', name);
log.error('Can not load "%s", it is not registered!\n ' +
'Perhaps you are missing some plugin?', name);
} else {
log.warn('Can not load "%s"!\n ' + e.stack, name);
log.error('Can not load "%s"!\n ' + e.stack, name);
}

emitter.emit('load_error', 'launcher', name);
return;
}

Expand Down
17 changes: 9 additions & 8 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ var isBinary = Object.create(null);
});

// TODO(vojta): instantiate preprocessors at the start to show warnings immediately
var createPreprocessor = function(config, basePath, injector) {
var createPreprocessor = function(config, basePath, injector, emitter) {
var patterns = Object.keys(config);
var alreadyDisplayedWarnings = Object.create(null);
var alreadyDisplayedErrors = Object.create(null);

return function(file, done) {
var thisFileIsBinary = isBinary[path.extname(file.originalPath)];
Expand All @@ -58,21 +58,22 @@ var createPreprocessor = function(config, basePath, injector) {
preprocessors.shift()(content, file, nextPreprocessor);
};
var instantiatePreprocessor = function(name) {
if (alreadyDisplayedWarnings[name]) {
if (alreadyDisplayedErrors[name]) {
return;
}

try {
preprocessors.push(injector.get('preprocessor:' + name));
} catch (e) {
if (e.message.indexOf('No provider for "preprocessor:' + name + '"') !== -1) {
log.warn('Can not load "%s", it is not registered!\n ' +
'Perhaps you are missing some plugin?', name);
log.error('Can not load "%s", it is not registered!\n ' +
'Perhaps you are missing some plugin?', name);
} else {
log.warn('Can not load "%s"!\n ' + e.stack, name);
log.error('Can not load "%s"!\n ' + e.stack, name);
}

alreadyDisplayedWarnings[name] = true;
emitter.emit('load_error', 'preprocessor', name);
alreadyDisplayedErrors[name] = true;
}
};

Expand All @@ -98,6 +99,6 @@ var createPreprocessor = function(config, basePath, injector) {
});
};
};
createPreprocessor.$inject = ['config.preprocessors', 'config.basePath', 'injector'];
createPreprocessor.$inject = ['config.preprocessors', 'config.basePath', 'injector', 'emitter'];

exports.createPreprocessor = createPreprocessor;
8 changes: 5 additions & 3 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ var createReporters = function(names, config, emitter, injector) {
reporters.push(injector.createChild([locals], ['reporter:' + name]).get('reporter:' + name));
} catch (e) {
if (e.message.indexOf('No provider for "reporter:' + name + '"') !== -1) {
log.warn('Can not load "%s", it is not registered!\n ' +
'Perhaps you are missing some plugin?', name);
log.error('Can not load "%s", it is not registered!\n ' +
'Perhaps you are missing some plugin?', name);
} else {
log.warn('Can not load "%s"!\n ' + e.stack, name);
log.error('Can not load "%s"!\n ' + e.stack, name);
}

emitter.emit('load_error', 'reporter', name);
}
});

Expand Down
5 changes: 5 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var log = logger.create();
var start = function(injector, config, launcher, globalEmitter, preprocess, fileList, webServer,
capturedBrowsers, socketServer, executor, done) {

var loadErrors = [];
globalEmitter.on('load_error', function(type, name) {
loadErrors.push([type, name]);
});

config.frameworks.forEach(function(framework) {
injector.get('framework:' + framework);
});
Expand Down

0 comments on commit 3e6900f

Please sign in to comment.