Skip to content

Commit

Permalink
fix: quiet flag only prints when set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Jan 17, 2017
1 parent e2f33b8 commit 4e47a5e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function apply (options, compiler) {
options = options || {};
var context = options.context || compiler.context;
options = assign({
formatter: formatter,
quiet: false
formatter: formatter
}, options, {
// Default Glob is any directory level of scss and/or sass file,
// under webpack's context and specificity changed via globbing patterns
Expand Down
4 changes: 2 additions & 2 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = function runCompilation (options, compiler, done) {
return file.errored;
});

if (!options.quiet) {
console.log(chalk.yellow(options.formatter(results)));
if (options.quiet === false) {
console.warn(options.formatter(results));
}

if (options.failOnError && errors.length) {
Expand Down
50 changes: 30 additions & 20 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var assign = require('object-assign');
var td = require('testdouble');
var StyleLintPlugin = require('../');
var pack = require('./helpers/pack');
var webpack = require('./helpers/webpack');
Expand Down Expand Up @@ -82,26 +83,6 @@ describe('stylelint-webpack-plugin', function () {
});
});

// TODO use snapshots to ensure something is printed to the console
it.skip('sends messages to console when quiet prop set to false', function () {
var config = {
context: './test/fixtures/syntax-error',
entry: './index',
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true
})
]
};

return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(1);
expect(stats.compilation.warnings).to.have.length(0);
});
});

it('fails when .stylelintrc is not a proper format', function () {
var config = {
entry: './index',
Expand All @@ -121,6 +102,35 @@ describe('stylelint-webpack-plugin', function () {
});
});

context('iff quiet is strictly false', function () {
beforeEach(function () {
td.replace(console, 'warn', td.function());
});

afterEach(function () {
td.reset();
});

it('sends messages to the console', function () {
var config = {
context: './test/fixtures/syntax-error',
entry: './index',
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: false
})
]
};

return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(1);
td.verify(console.warn(td.matchers.contains('✖')));
});
});
});

context('without StyleLintPlugin configuration', function () {
var config = {
context: './test/fixtures/lint-free',
Expand Down

0 comments on commit 4e47a5e

Please sign in to comment.