nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 49 forks source link

Custom error handling #132

Closed tomyam1 closed 9 years ago

tomyam1 commented 9 years ago

I would like to integrate my custom error handling to karma-browserify, e.g. notify with node-notifier when there is a bundling error.

Currently karma-browserify just logs errors to the console and it takes me some time to realize that an error has occurred. Especially when tests are run due to a change of a watched file.

I couldn't find any API for that, but this monkey-patch seems to work fine:

// monkey patch karma-browserify before karma starts
var KarmaBrowserify = require('karma-browserify');

KarmaBrowserify['framework:browserify'][1] = function framework(injector, bro) {
  var w = injector.invoke(bro.framework);
  w.on('bundled', function(err, content) {
    if (err) {
      // Custom error handler
    }
  });
  return w;
};

Is there any correct way to do that? If not, would you consider adding such mechanism?

bendrucker commented 9 years ago

No great answer here. An error event will crash the process unless we only emit if there's a listener. There's already some non-standard events so I think it's reasonable. Will take a PR.

tomyam1 commented 9 years ago

I see. For now I'll stay with my current solution. Thanks for the quick response @bendrucker !