Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Can this work with this.emitError (Loader API) ? #52

Open
ajbrun opened this issue Jan 12, 2017 · 0 comments
Open

Can this work with this.emitError (Loader API) ? #52

ajbrun opened this issue Jan 12, 2017 · 0 comments

Comments

@ajbrun
Copy link

ajbrun commented Jan 12, 2017

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'); }

image

@michael-ciniawsky michael-ciniawsky changed the title Can this work with webpack.emitError? Can this work with this.emitError (Loader API) ? Aug 27, 2018
@michael-ciniawsky michael-ciniawsky added this to the 2.0.1 milestone Aug 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants