-
-
Notifications
You must be signed in to change notification settings - Fork 50
Can this work with this.emitError
(Loader API) ? #52
Description
I was hoping to make a pull request for this, but I've run into difficulties, so I wondering if anyone else has any thoughts/suggestions. My idea was to allow this loader to work with the emitError function that webpack provides in its loaders. This could either be done by default or via a parameter, but I've not managed to get the basic functionality working yet.
I was aiming towards something like what eslint loader does:
https://github.com/MoOx/eslint-loader/blob/master/index.js#L102
Which with the webpack hot middleware will output a response to the browser similar to what's shown here:
webpack-contrib/webpack-hot-middleware#9 (comment)
So far I have this, but it doesn't emit the error as expected for a failing test. It shows the error in the console, just not on screen or in the browser's console as it usually does with an emitError.
var Mocha = require('mocha');
var babel = require('babel-core/register');
module.exports = function(content, map) {
var webpack = this;
var mocha = new Mocha({
compilers: {
js: babel
}
});
mocha.ui('bdd');
mocha.addFile(this.resourcePath);
mocha.run().on("fail", function(test, err) {
webpack.emitError(err);
});
return "console.log('Mocha loader run at '+new Date().toLocaleString());";
};
I have however found that if I remove all mocha code, and just emitError on condition of matching a string in the content, that works (albeit not on initial load), so the issue is the mocha code, which I haven't had much experience with.
if (content.indexOf('make error') >= 0) { //Works as expected webpack.emitError('error test'); }