From 97761d724e6fa26d8dbde4a544ddb7cb3795f568 Mon Sep 17 00:00:00 2001 From: nicolaslt Date: Thu, 19 Jul 2018 08:59:01 +0100 Subject: [PATCH] Fix not returning execution flow control to webpack when cache option is enabled and one of the files has a linting error (#224) * Fix webpack hanging when `failOnError` and are enabled and there is a formatting error * Add tests for the combination of emit+async+failOnError --- index.js | 10 ++++- test/fail-on-error/async-and-emit.js | 56 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/fail-on-error/async-and-emit.js diff --git a/index.js b/index.js index d16086c..d9062b1 100644 --- a/index.js +++ b/index.js @@ -216,8 +216,14 @@ module.exports = function(input, map) { if (err) { return callback(err) } - printLinterOutput(res || {}, config, webpack) - return callback(null, input, map) + + try { + printLinterOutput(res || {}, config, webpack) + } + catch (e) { + err = e + } + return callback(err, input, map) } ) } diff --git a/test/fail-on-error/async-and-emit.js b/test/fail-on-error/async-and-emit.js new file mode 100644 index 0000000..34a3e35 --- /dev/null +++ b/test/fail-on-error/async-and-emit.js @@ -0,0 +1,56 @@ +var test = require("ava") + +var webpack = require("webpack") +var conf = require("./utils/conf") + +test.cb("emits errors in async mode", function(t) { + t.plan(1) + webpack(conf( + { + cache: true, + entry: "./test/fixtures/error.js", + },{ + failOnError: true, + emitError: true, + cache: true, + } + ), + function(err, stats) { + if (err) { + throw err + } + + // console.log(stats.compilation.errors) + t.true( + stats.hasErrors(), + "a file that contains eslint errors should return error" + ) + t.end() + }) +}) + +test.cb("correctly indentifies a success", function(t) { + t.plan(1) + webpack(conf( + { + cache: true, + entry: "./test/fixtures/good.js", + },{ + failOnError: true, + emitError: true, + cache: true, + } + ), + function(err, stats) { + if (err) { + throw err + } + + // console.log(stats.compilation.errors) + t.false( + stats.hasErrors(), + "a file that doesn't contains eslint errors should not return errors" + ) + t.end() + }) +})