Skip to content

Commit 18eb80e

Browse files
authored
fix: duplicated displayed errors & warnings (#56)
* tests: better names for fixtures
1 parent 877e4ea commit 18eb80e

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

lib/run-compilation.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ module.exports = function runCompilation(options, compiler, done) {
1616

1717
linter(options)
1818
.then(function linterSuccess(lint) {
19-
warnings = lint.results.filter(function (f) {
20-
return f.warnings && f.warnings.length;
19+
var results = lint.results;
20+
21+
warnings = results.filter(function (file) {
22+
return !file.errored && file.warnings && file.warnings.length;
2123
});
2224

23-
errors = lint.results.filter(function (f) {
24-
return f.errored;
25+
errors = results.filter(function (file) {
26+
return file.errored;
2527
});
2628

2729
if (!options.quiet) {
28-
console.log(chalk.yellow(options.formatter(lint.results)));
30+
console.log(chalk.yellow(options.formatter(results)));
2931
}
3032

3133
if (options.failOnError && errors.length) {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/index.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,16 @@ describe('stylelint-webpack-plugin', function () {
2222
});
2323
});
2424

25-
it('sends errors properly', function () {
25+
it('sends errors to the errors output only', function () {
2626
var config = {
2727
context: './test/fixtures/test3',
2828
entry: './index'
2929
};
3030

3131
return pack(assign({}, baseConfig, config))
3232
.then(function (stats) {
33-
expect(stats.compilation.errors).to.have.length(1);
34-
});
35-
});
36-
37-
it.skip('fails when .stylelintrc is not a proper format', function () {
38-
var badConfigFilePath = getPath('./.badstylelintrc');
39-
var config = {
40-
entry: './index',
41-
plugins: [
42-
new StyleLintPlugin({
43-
configFile: badConfigFilePath
44-
})
45-
]
46-
};
47-
48-
return pack(assign({}, baseConfig, config))
49-
.then(function (stats) {
50-
expect(stats.compilation.errors).to.have.length(0);
33+
expect(stats.compilation.errors).to.have.length(1, 'should have one error');
34+
expect(stats.compilation.warnings).to.have.length(0, 'should have no warnings');
5135
});
5236
});
5337

@@ -84,19 +68,14 @@ describe('stylelint-webpack-plugin', function () {
8468

8569
it('sends warnings properly', function () {
8670
var config = {
87-
context: './test/fixtures/test8',
88-
entry: './index',
89-
plugins: [
90-
new StyleLintPlugin({
91-
quiet: true,
92-
configFile: configFilePath
93-
})
94-
]
71+
context: './test/fixtures/rule-warning',
72+
entry: './index'
9573
};
9674

9775
return pack(assign({}, baseConfig, config))
9876
.then(function (stats) {
9977
expect(stats.compilation.warnings).to.have.length(1);
78+
expect(stats.compilation.errors).to.have.length(0);
10079
});
10180
});
10281

@@ -116,9 +95,9 @@ describe('stylelint-webpack-plugin', function () {
11695
});
11796
});
11897

119-
it('send messages to console when css file with errors and quiet props set to false', function () {
98+
it('sends messages to console when css file with errors and quiet props set to false', function () {
12099
var config = {
121-
context: './test/fixtures/test10',
100+
context: './test/fixtures/syntax-error',
122101
entry: './index',
123102
plugins: [
124103
new StyleLintPlugin({
@@ -129,7 +108,7 @@ describe('stylelint-webpack-plugin', function () {
129108

130109
return pack(assign({}, baseConfig, config))
131110
.then(function (stats) {
132-
expect(stats.compilation.warnings).to.have.length(1);
111+
expect(stats.compilation.warnings).to.have.length(0);
133112
expect(stats.compilation.errors).to.have.length(1);
134113
});
135114
});
@@ -174,4 +153,21 @@ describe('stylelint-webpack-plugin', function () {
174153
});
175154
});
176155
});
156+
157+
it.skip('fails when .stylelintrc is not a proper format', function () {
158+
var badConfigFilePath = getPath('./.badstylelintrc');
159+
var config = {
160+
entry: './index',
161+
plugins: [
162+
new StyleLintPlugin({
163+
configFile: badConfigFilePath
164+
})
165+
]
166+
};
167+
168+
return pack(assign({}, baseConfig, config))
169+
.then(function (stats) {
170+
expect(stats.compilation.errors).to.have.length(0);
171+
});
172+
});
177173
});

0 commit comments

Comments
 (0)