Skip to content

Commit

Permalink
Merge pull request #183 from earshinov/master
Browse files Browse the repository at this point in the history
Separate errors with newlines.
  • Loading branch information
shama committed Mar 29, 2018
2 parents 8336e66 + f8f53ae commit 505ad81
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ module.exports = function (options, wp, done) {
var jsonStats = stats ? stats.toJson() || {} : {};
var errors = jsonStats.errors || [];
if (errors.length) {
var errorMessage = errors.reduce(function (resultMessage, nextError) {
resultMessage += nextError.toString();
return resultMessage;
}, '');
var errorMessage = errors.join('\n');
var compilationError = new PluginError('webpack-stream', errorMessage);
if (!options.watch) {
self.emit('error', compilationError);
Expand Down
10 changes: 10 additions & 0 deletions test/fake-error-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function fakeErrorLoader (text) {
this.cacheable();

var fakeError = new Error('Fake error');
// delete stack trace prevent it from showing up in webpack output
delete fakeError.stack;
this.emitError(fakeError);

return text;
};
35 changes: 35 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,38 @@ test('no options', function (t) {
});
stream.end();
});

test('error formatting', function (t) {
t.plan(2);
var expectedMessage =
'./test/fixtures/entry.js\n' +
'Fake error\n' +
'./test/fixtures/one.js\n' +
'Fake error\n' +
' @ ./test/fixtures/entry.js 3:10-29\n' +
'./test/fixtures/chunk.js\n' +
'Fake error\n' +
' @ ./test/fixtures/entry.js 4:0-6:2';
var entry = fs.src('test/fixtures/entry.js');
var stream = webpack({
quiet: true,
config: {
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
use: './test/fake-error-loader'
}
]
}
}
});
stream.on('error', function (err) {
t.equal(err.message, expectedMessage, 'error message');
});
stream.on('compilation-error', function (err) {
t.equal(err.message, expectedMessage, 'compilation-error message');
});
entry.pipe(stream);
});

0 comments on commit 505ad81

Please sign in to comment.