Skip to content

Commit

Permalink
fix: duplicated displayed errors & warnings (#56)
Browse files Browse the repository at this point in the history
* tests: better names for fixtures
  • Loading branch information
JaKXz authored Jan 9, 2017
1 parent 877e4ea commit 18eb80e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
12 changes: 7 additions & 5 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 26 additions & 30 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,16 @@ 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'
};

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

Expand Down Expand Up @@ -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);
});
});

Expand All @@ -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({
Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 18eb80e

Please sign in to comment.