Skip to content

Commit

Permalink
feat: output errors in error constructor (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
crash7 authored and JaKXz committed Jun 27, 2017
1 parent 59904a2 commit 07d57d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/run-compilation.js
@@ -1,6 +1,5 @@
'use strict';

var chalk = require('chalk');
var R = require('ramda');
var linter = require('./linter');
var errorMessage = require('./constants').errorMessage;
Expand Down Expand Up @@ -41,12 +40,12 @@ module.exports = function runCompilation (options, compiler, done) {

compiler.plugin('after-emit', function afterEmit (compilation, callback) {
if (warnings.length) {
compilation.warnings.push(chalk.yellow(options.formatter(warnings)));
compilation.warnings.push(new Error(options.formatter(warnings)));
warnings = [];
}

if (errors.length) {
compilation.errors.push(chalk.red(options.formatter(errors)));
compilation.errors.push(new Error(options.formatter(errors)));
errors = [];
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,6 @@
},
"dependencies": {
"arrify": "^1.0.1",
"chalk": "^1.1.3",
"minimatch": "^3.0.3",
"object-assign": "^4.1.0",
"ramda": "^0.24.1",
Expand Down
11 changes: 7 additions & 4 deletions test/index.test.js
Expand Up @@ -33,8 +33,9 @@ describe('stylelint-webpack-plugin', function () {
return pack(assign({}, baseConfig, { context: path.resolve('./test/fixtures/multiple-sources') }))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(1);
expect(stats.compilation.errors[0]).to.contain('test/fixtures/multiple-sources/_second.scss');
expect(stats.compilation.errors[0]).to.contain('test/fixtures/multiple-sources/test.scss');
expect(stats.compilation.errors[0]).to.be.an.instanceof(Error);
expect(stats.compilation.errors[0].message).to.contain('test/fixtures/multiple-sources/_second.scss');
expect(stats.compilation.errors[0].message).to.contain('test/fixtures/multiple-sources/test.scss');
});
});

Expand Down Expand Up @@ -206,7 +207,8 @@ describe('stylelint-webpack-plugin', function () {
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(0);
expect(stats.compilation.warnings).to.have.length(1);
expect(stats.compilation.warnings[0]).to.contain('✖');
expect(stats.compilation.warnings[0]).to.be.an.instanceof(Error);
expect(stats.compilation.warnings[0].message).to.contain('✖');
});
});

Expand All @@ -215,7 +217,8 @@ describe('stylelint-webpack-plugin', function () {
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(0);
expect(stats.compilation.warnings).to.have.length(1);
expect(stats.compilation.warnings[0]).to.contain('⚠');
expect(stats.compilation.warnings[0]).to.be.an.instanceof(Error);
expect(stats.compilation.warnings[0].message).to.contain('⚠');
});
});
});
Expand Down

0 comments on commit 07d57d6

Please sign in to comment.