From a15e54c9ceee62868948db9723d880c67623d5d7 Mon Sep 17 00:00:00 2001 From: Jason Kurian Date: Wed, 14 Feb 2018 20:55:02 -0500 Subject: [PATCH] fix: remove duplicate error/warning logging (#130) * style: correct td.verify calls to match documentation * style: use const/lets in lint-dirty-modules.test.js --- README.md | 1 - lib/run-compilation.js | 4 -- test/helpers/base-config.js | 1 - test/index.test.js | 49 ++++++---------------- test/lib/lint-dirty-modules-plugin.test.js | 48 ++++++++++----------- 5 files changed, 36 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index c8ffa56..67f34fa 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ See [stylelint options](http://stylelint.io/user-guide/node-api/#options) for th * `formatter`: Use a custom formatter to print errors to the console. Default: `require('stylelint').formatters.string` * `lintDirtyModulesOnly`: Lint only changed files, skip lint on start. Default: `false` * [`syntax`](https://stylelint.io/user-guide/node-api/#syntax): e.g. use `'scss'` to lint .scss files. Default: `undefined` -* `quiet`: Prints `stylelint` output directly to the console if negated. Default: `true`. ## Errors diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 4be0aed..d3ac9c2 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -27,10 +27,6 @@ module.exports = function runCompilation (options, compiler, done) { errors = results.filter(fileHasErrors); } - if (options.quiet === false) { - console.warn(options.formatter(results)); - } - if (options.failOnError && errors.length) { done(new Error(errorMessage)); } else { diff --git a/test/helpers/base-config.js b/test/helpers/base-config.js index 001bb48..606482f 100644 --- a/test/helpers/base-config.js +++ b/test/helpers/base-config.js @@ -12,7 +12,6 @@ var baseConfig = { }, plugins: [ new StyleLintPlugin({ - quiet: true, configFile: configFilePath }) ] diff --git a/test/index.test.js b/test/index.test.js index b8ae77e..4a5fd72 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -13,6 +13,16 @@ const configFilePath = getPath('./.stylelintrc'); const errorMessage = require('../lib/constants').errorMessage; describe('stylelint-webpack-plugin', function () { + beforeEach(function () { + td.replace(console, 'warn', td.function()); + }); + + afterEach(function () { + // See https://github.com/JaKXz/stylelint-webpack-plugin/issues/61 + td.verify(console.warn(), { times: 0, ignoreExtraArgs: true }); + td.reset(); + }); + it('works with a simple file', function () { return pack(assign({}, baseConfig, { context: path.resolve('./test/fixtures/lint-free') })) .then(function (stats) { @@ -53,7 +63,6 @@ describe('stylelint-webpack-plugin', function () { plugins: [ new StyleLintPlugin({ configFile: configFilePath, - quiet: true, failOnError: true }) ] @@ -71,8 +80,7 @@ describe('stylelint-webpack-plugin', function () { context: path.resolve('./test/fixtures/single-error'), plugins: [ new StyleLintPlugin({ - configFile: getPath('./.badstylelintrc'), - quiet: true + configFile: getPath('./.badstylelintrc') }) ] }; @@ -84,34 +92,6 @@ 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 () { - const config = { - context: path.resolve('./test/fixtures/syntax-error'), - 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(/.*/i))); - }); - }); - }); - context('without StyleLintPlugin configuration', function () { const config = { plugins: [ @@ -141,8 +121,7 @@ describe('stylelint-webpack-plugin', function () { context: path.resolve('./test/fixtures/single-error'), plugins: [ new StyleLintPlugin({ - configFile: configFilePath, - quiet: true + configFile: configFilePath }), new webpack.NoErrorsPlugin() ] @@ -159,7 +138,6 @@ describe('stylelint-webpack-plugin', function () { plugins: [ new StyleLintPlugin({ configFile: configFilePath, - quiet: true, failOnError: true }), new webpack.NoErrorsPlugin() @@ -188,7 +166,6 @@ describe('stylelint-webpack-plugin', function () { plugins: [ new StyleLintPlugin({ configFile: configFilePath, - quiet: true, emitErrors: false }) ] @@ -230,7 +207,6 @@ describe('stylelint-webpack-plugin', function () { plugins: [ new StyleLintPlugin({ configFile: configFilePath, - quiet: true, lintDirtyModulesOnly: true }) ] @@ -249,7 +225,6 @@ describe('stylelint-webpack-plugin', function () { plugins: [ new StyleLintPlugin({ configFile: configFilePath, - quiet: true, lintDirtyModulesOnly: true, emitErrors: false }) diff --git a/test/lib/lint-dirty-modules-plugin.test.js b/test/lib/lint-dirty-modules-plugin.test.js index a42c1a5..0feb9c5 100644 --- a/test/lib/lint-dirty-modules-plugin.test.js +++ b/test/lib/lint-dirty-modules-plugin.test.js @@ -1,19 +1,19 @@ 'use strict'; -var td = require('testdouble'); -var formatter = require('stylelint').formatters.string; +const td = require('testdouble'); +const formatter = require('stylelint').formatters.string; -var runCompilation = td.replace('../../lib/run-compilation'); +const runCompilation = td.replace('../../lib/run-compilation'); -var LintDirtyModulesPlugin = require('../../lib/lint-dirty-modules-plugin'); +const LintDirtyModulesPlugin = require('../../lib/lint-dirty-modules-plugin'); -var configFilePath = getPath('./.stylelintrc'); -var glob = require('../../lib/constants').defaultFilesGlob; +const configFilePath = getPath('./.stylelintrc'); +const glob = require('../../lib/constants').defaultFilesGlob; describe('lint-dirty-modules-plugin', function () { - var LintDirtyModulesPluginCloned; - var compilerMock; - var optionsMock; + let LintDirtyModulesPluginCloned; + let compilerMock; + let optionsMock; beforeEach(function () { LintDirtyModulesPluginCloned = function () { @@ -38,15 +38,15 @@ describe('lint-dirty-modules-plugin', function () { }); it('lint is called on "emit"', function () { - var lintStub = td.function(); - var doneStub = td.function(); + const lintStub = td.function(); + const doneStub = td.function(); LintDirtyModulesPluginCloned.prototype.lint = lintStub; - var compilationMock = { + const compilationMock = { fileTimestamps: { '/updated.scss': 5 } }; - var plugin = new LintDirtyModulesPluginCloned(compilerMock, optionsMock); + const plugin = new LintDirtyModulesPluginCloned(compilerMock, optionsMock); compilerMock.callback(compilationMock, doneStub); @@ -55,14 +55,14 @@ describe('lint-dirty-modules-plugin', function () { }); context('#lint()', function () { - var getChangedFilesStub; - var doneStub; - var compilationMock; - var fileTimestamps = { + let getChangedFilesStub; + let doneStub; + let compilationMock; + const fileTimestamps = { '/test/changed.scss': 5, '/test/newly-created.scss': 5 }; - var pluginMock; + let pluginMock; beforeEach(function () { getChangedFilesStub = td.function(); doneStub = td.function(); @@ -86,8 +86,8 @@ describe('lint-dirty-modules-plugin', function () { td.verify(doneStub()); expect(pluginMock.isFirstRun).to.eql(false); - td.verify(getChangedFilesStub, {times: 0, ignoreExtraArgs: true}); - td.verify(runCompilation, {times: 0, ignoreExtraArgs: true}); + td.verify(getChangedFilesStub(), { times: 0, ignoreExtraArgs: true }); + td.verify(runCompilation(), { times: 0, ignoreExtraArgs: true }); }); it('runCompilation is not called if files are not changed', function () { @@ -96,7 +96,7 @@ describe('lint-dirty-modules-plugin', function () { LintDirtyModulesPluginCloned.prototype.lint.call(pluginMock, compilationMock, doneStub); td.verify(doneStub()); - td.verify(runCompilation, {times: 0, ignoreExtraArgs: true}); + td.verify(runCompilation(), { times: 0, ignoreExtraArgs: true }); }); it('runCompilation is called if styles are changed', function () { @@ -113,7 +113,7 @@ describe('lint-dirty-modules-plugin', function () { }); context('#getChangedFiles()', function () { - var pluginMock; + let pluginMock; before(function () { pluginMock = { compiler: compilerMock, @@ -129,13 +129,13 @@ describe('lint-dirty-modules-plugin', function () { }); it('returns changed style files', function () { - var fileTimestamps = { + const fileTimestamps = { '/test/changed.scss': 20, '/test/changed.js': 20, '/test/newly-created.scss': 15 }; - var changedFiles = LintDirtyModulesPluginCloned.prototype.getChangedFiles.call(pluginMock, fileTimestamps, glob); + const changedFiles = LintDirtyModulesPluginCloned.prototype.getChangedFiles.call(pluginMock, fileTimestamps, glob); expect(changedFiles).to.eql([ '/test/changed.scss',