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

Conversation

srawlins
Copy link
Contributor

@srawlins srawlins commented Nov 7, 2014

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.

Update

This PR is now ready, barring the issue with changing the signature of createPreprocessor that I highlight below. I did not add any tests, but would be happy to if someone could point me the way there.

Example

I put the following into a config file:

preprocessors: {
  "**/*.js": ["tea"]
},
reporters: ["progress", "regress"],
browsers: ["Chrome", "Crime"],

and started karma:

$ ../bin/karma start my.conf.js 
16 07 2015 13:14:36.172:ERROR [reporter]: Cannot load reporter "regress": it is not registered! Perhaps you are missing some plugin?
16 07 2015 13:14:36.182:ERROR [preprocess]: Cannot load preprocessor "tea": it is not registered! Perhaps you are missing some plugin?
16 07 2015 13:14:36.189:INFO [karma]: Karma v0.13.0 server started at http://localhost:9876/
16 07 2015 13:14:36.189:ERROR [launcher]: Cannot load browser "Chrome": it is not registered! Perhaps you are missing some plugin?
16 07 2015 13:14:36.189:ERROR [launcher]: Cannot load browser "Crime": it is not registered! Perhaps you are missing some plugin?

then karma promptly exits.

Closes #855

@@ -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]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As each error is caught, they are collected here. After this, however, I can't figure out where to perform a final check of whether loadErrors is empty or not...

@vojtajina
Copy link
Contributor

Karma should fail if any plugin can't be instantiated. That is: launcher, preprocessor, reporter.

Btw, I like the idea of collecting all errors and then failing, so that user sees all the errors and not only the first one.

Here are all the places where Karma instantiate plugins and thus a fatal error can happen (in order in which it happens):

  1. Loading plugins (loading the DI modules):
    modules = modules.concat(plugin.resolve(config.plugins));
  2. Instantiate reporters
    reporters.push(injector.createChild([locals], ['reporter:' + name]).get('reporter:' + name));
  3. Instantiating frameworks (inside start function):
    config.frameworks.forEach(function(framework) {
  4. Start browsers (after the webserver is ready listening):
    injector.invoke(launcher.launch, launcher).forEach(function(browserLauncher) {
  5. Instantiate preprocessors (this happens lazily, once the preprocessor is needed; we need to change that and instantiate all needed preprocessors ahead, inside createPreprocessor factory)
    config[patterns[i]].forEach(instantiatePreprocessor);

Thus, I would add the check into the webserver listener, after launching browsers (), and fail Karma if any error occurred. At that point, all of the plugins were instantiated, except preprocessors. We need to change preprocessors to instantiate all needed preprocessors ahead (in the createPreprocessor factory), instead of lazily.

I'm sorry this is confusing. I think it would be good to refactor Karma to instantiate everything first. Right now, "instantiating things" is kind of tangled together with bootstrapping (this is probably more efficient, but harder to understand). I wish I did it differently;-)

@srawlins Let me know if I can help you more. This is very valuable work you are doing!

@dignifiedquire
Copy link
Member

@srawlins any chance for you updating this PR with the suggestions from @vojtajina. I would really appreciate it and I promise a shorter feedback cycle!

@srawlins
Copy link
Contributor Author

Hi Friedel, i'm actually on vacation until June 20. Please feel free to
submit a different PR with my commits if you want this in soon. Otherwise I
can try to finish at the end of June.
On May 17, 2015 7:27 PM, "Friedel Ziegelmayer" notifications@github.com
wrote:

@srawlins https://github.com/srawlins any chance for you updating this
PR with the suggestions from @vojtajina https://github.com/vojtajina. I
would really appreciate it and I promise a shorter feedback cycle!


Reply to this email directly or view it on GitHub
#1239 (comment).

@dignifiedquire
Copy link
Member

Thanks @srawlins for the quick answer, I'll see where we're at until June the 20th and update this pr if I get to doing it myself before.

@dignifiedquire
Copy link
Member

hey @srawlins any news on you getting back?

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.

Closes karma-runner#855
@srawlins srawlins force-pushed the issue-855-fail-on-load-errors branch from 3e6900f to 73432eb Compare July 16, 2015 20:28
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@srawlins
Copy link
Contributor Author

Hi @dignifiedquire , I've updated this with @vojtajina's suggestions, and it's working great! There's one problem though: I've changed the signature of createPreprocessor, adding emitter:

var createPreprocessor = function(config, basePath, injector, emitter) {

Travis revealed this as a problem, I think specifically with the karma-browserify which calls createPreprocessor. I don't know karma's ecosystem well enough to know how big a problem this is. But I don't see another way around my implementation.

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

@dignifiedquire
Copy link
Member

As far as I understand this di business, there should be no issue changing the signature, as it's only used as a factory function, which receives it's arguments through the injector

@srawlins
Copy link
Contributor Author

Yeah, I think you're right. Unfortunately, karma-browserify calls createPreprocessor directly.

@dignifiedquire
Copy link
Member

@srawlins any updates?

@srawlins
Copy link
Contributor Author

Closing to try to work this another way with #1931

@srawlins srawlins closed this Feb 29, 2016
@srawlins srawlins deleted the issue-855-fail-on-load-errors branch February 29, 2016 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throw an error on not found browsers
4 participants