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

feat: Fail on launcher-, reporter-, or preprocessor-load errors. #1239

Closed
Closed
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
9 changes: 5 additions & 4 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ 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('Cannot load browser "%s": it is not registered! ' +
'Perhaps you are missing some plugin?', name)
} else {
log.warn('Can not load "%s"!\n ' + e.stack, name)
log.error('Cannot load browser "%s"!\n ' + e.stack, name)
}

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

// TODO(vojta): remove in v1.0 (BC for old launchers)
Expand Down
35 changes: 19 additions & 16 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ extensions.forEach(function (extension) {
})

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use {} instead


return function (file, done) {
var patterns = Object.keys(config)
Expand All @@ -45,24 +46,25 @@ var createPreprocessor = function (config, basePath, injector) {
return done()
}

preprocessors.shift()(content, file, nextPreprocessor)
}
var instantiatePreprocessor = function (name) {
if (alreadyDisplayedWarnings[name]) {
return
preprocessors.shift()(content, file, nextPreprocessor);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No semicolons ;)

var instantiatePreprocessor = function(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('Cannot load preprocessor "%s": it is not registered! ' +
'Perhaps you are missing some plugin?', name)
} else {
log.warn('Can not load "%s"!\n ' + e.stack, name)
log.error('Cannot load preprocessor "%s"!\n ' + e.stack, name)
}

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

Expand All @@ -83,10 +85,11 @@ var createPreprocessor = function (config, basePath, injector) {
if (err) {
throw err
}
nextPreprocessor(null, thisFileIsBinary ? buffer : buffer.toString())
})
}
}
createPreprocessor.$inject = ['config.preprocessors', 'config.basePath', 'injector']
file.sha = sha1(buffer);
nextPreprocessor(null, thisFileIsBinary ? buffer : buffer.toString());
});
};
};
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 @@ -91,11 +91,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('Cannot load reporter "%s": it is not registered! ' +
'Perhaps you are missing some plugin?', name)
} else {
log.warn('Can not load "%s"!\n ' + e.stack, name)
log.error('Cannot load reporter "%s"!\n ' + e.stack, name)
}

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

Expand Down
11 changes: 11 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var Server = function (cliOptions, done) {

this.log = logger.create()

this.loadErrors = []

var config = cfg.parseConfig(cliOptions.configFile, cliOptions)

var modules = [{
Expand Down Expand Up @@ -105,6 +107,10 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS
capturedBrowsers, socketServer, executor, done) {
var self = this

this.on('load_error', function(type, name) {
self.loadErrors.push([type, name])
})

config.frameworks.forEach(function (framework) {
self._injector.get('framework:' + framework)
})
Expand Down Expand Up @@ -143,6 +149,11 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS
singleRunDoneBrowsers[browserLauncher.id] = false
})
}

if (self.loadErrors.length > 0) {
// At least one plugin failed to load.
process.exit(1)
}
})
}

Expand Down