From 18eb80eca5466506360e673685605140fb479e63 Mon Sep 17 00:00:00 2001 From: Jason Kurian Date: Sun, 8 Jan 2017 19:20:19 -0500 Subject: [PATCH] fix: duplicated displayed errors & warnings (#56) * tests: better names for fixtures --- lib/run-compilation.js | 12 ++-- .../fixtures/{test8 => rule-warning}/index.js | 0 .../{test8 => rule-warning}/test.scss | 0 .../{test10 => syntax-error}/index.js | 0 .../{test10 => syntax-error}/test.scss | 0 test/index.js | 56 +++++++++---------- 6 files changed, 33 insertions(+), 35 deletions(-) rename test/fixtures/{test8 => rule-warning}/index.js (100%) rename test/fixtures/{test8 => rule-warning}/test.scss (100%) rename test/fixtures/{test10 => syntax-error}/index.js (100%) rename test/fixtures/{test10 => syntax-error}/test.scss (100%) diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 7abf4bc..cc0395e 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -16,16 +16,18 @@ module.exports = function runCompilation(options, compiler, done) { linter(options) .then(function linterSuccess(lint) { - warnings = lint.results.filter(function (f) { - return f.warnings && f.warnings.length; + var results = lint.results; + + warnings = results.filter(function (file) { + return !file.errored && file.warnings && file.warnings.length; }); - errors = lint.results.filter(function (f) { - return f.errored; + errors = results.filter(function (file) { + return file.errored; }); if (!options.quiet) { - console.log(chalk.yellow(options.formatter(lint.results))); + console.log(chalk.yellow(options.formatter(results))); } if (options.failOnError && errors.length) { diff --git a/test/fixtures/test8/index.js b/test/fixtures/rule-warning/index.js similarity index 100% rename from test/fixtures/test8/index.js rename to test/fixtures/rule-warning/index.js diff --git a/test/fixtures/test8/test.scss b/test/fixtures/rule-warning/test.scss similarity index 100% rename from test/fixtures/test8/test.scss rename to test/fixtures/rule-warning/test.scss diff --git a/test/fixtures/test10/index.js b/test/fixtures/syntax-error/index.js similarity index 100% rename from test/fixtures/test10/index.js rename to test/fixtures/syntax-error/index.js diff --git a/test/fixtures/test10/test.scss b/test/fixtures/syntax-error/test.scss similarity index 100% rename from test/fixtures/test10/test.scss rename to test/fixtures/syntax-error/test.scss diff --git a/test/index.js b/test/index.js index 5912aa2..1713285 100644 --- a/test/index.js +++ b/test/index.js @@ -22,7 +22,7 @@ describe('stylelint-webpack-plugin', function () { }); }); - it('sends errors properly', function () { + it('sends errors to the errors output only', function () { var config = { context: './test/fixtures/test3', entry: './index' @@ -30,24 +30,8 @@ describe('stylelint-webpack-plugin', function () { return pack(assign({}, baseConfig, config)) .then(function (stats) { - expect(stats.compilation.errors).to.have.length(1); - }); - }); - - it.skip('fails when .stylelintrc is not a proper format', function () { - var badConfigFilePath = getPath('./.badstylelintrc'); - var config = { - entry: './index', - plugins: [ - new StyleLintPlugin({ - configFile: badConfigFilePath - }) - ] - }; - - return pack(assign({}, baseConfig, config)) - .then(function (stats) { - expect(stats.compilation.errors).to.have.length(0); + expect(stats.compilation.errors).to.have.length(1, 'should have one error'); + expect(stats.compilation.warnings).to.have.length(0, 'should have no warnings'); }); }); @@ -84,19 +68,14 @@ describe('stylelint-webpack-plugin', function () { it('sends warnings properly', function () { var config = { - context: './test/fixtures/test8', - entry: './index', - plugins: [ - new StyleLintPlugin({ - quiet: true, - configFile: configFilePath - }) - ] + context: './test/fixtures/rule-warning', + entry: './index' }; return pack(assign({}, baseConfig, config)) .then(function (stats) { expect(stats.compilation.warnings).to.have.length(1); + expect(stats.compilation.errors).to.have.length(0); }); }); @@ -116,9 +95,9 @@ describe('stylelint-webpack-plugin', function () { }); }); - it('send messages to console when css file with errors and quiet props set to false', function () { + it('sends messages to console when css file with errors and quiet props set to false', function () { var config = { - context: './test/fixtures/test10', + context: './test/fixtures/syntax-error', entry: './index', plugins: [ new StyleLintPlugin({ @@ -129,7 +108,7 @@ describe('stylelint-webpack-plugin', function () { return pack(assign({}, baseConfig, config)) .then(function (stats) { - expect(stats.compilation.warnings).to.have.length(1); + expect(stats.compilation.warnings).to.have.length(0); expect(stats.compilation.errors).to.have.length(1); }); }); @@ -174,4 +153,21 @@ describe('stylelint-webpack-plugin', function () { }); }); }); + + it.skip('fails when .stylelintrc is not a proper format', function () { + var badConfigFilePath = getPath('./.badstylelintrc'); + var config = { + entry: './index', + plugins: [ + new StyleLintPlugin({ + configFile: badConfigFilePath + }) + ] + }; + + return pack(assign({}, baseConfig, config)) + .then(function (stats) { + expect(stats.compilation.errors).to.have.length(0); + }); + }); });