Skip to content

Commit

Permalink
Merge 9ee0fab into ad3158d
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Jan 31, 2018
2 parents ad3158d + 9ee0fab commit f6b3cfb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 67 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions lib/run-compilation.js
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion test/helpers/base-config.js
Expand Up @@ -12,7 +12,6 @@ var baseConfig = {
},
plugins: [
new StyleLintPlugin({
quiet: true,
configFile: configFilePath
})
]
Expand Down
49 changes: 12 additions & 37 deletions test/index.test.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -53,7 +63,6 @@ describe('stylelint-webpack-plugin', function () {
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
failOnError: true
})
]
Expand All @@ -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')
})
]
};
Expand All @@ -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: [
Expand Down Expand Up @@ -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()
]
Expand All @@ -159,7 +138,6 @@ describe('stylelint-webpack-plugin', function () {
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
failOnError: true
}),
new webpack.NoErrorsPlugin()
Expand Down Expand Up @@ -188,7 +166,6 @@ describe('stylelint-webpack-plugin', function () {
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
emitErrors: false
})
]
Expand Down Expand Up @@ -230,7 +207,6 @@ describe('stylelint-webpack-plugin', function () {
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
lintDirtyModulesOnly: true
})
]
Expand All @@ -249,7 +225,6 @@ describe('stylelint-webpack-plugin', function () {
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
lintDirtyModulesOnly: true,
emitErrors: false
})
Expand Down
48 changes: 24 additions & 24 deletions 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 () {
Expand All @@ -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);

Expand All @@ -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();
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -113,7 +113,7 @@ describe('lint-dirty-modules-plugin', function () {
});

context('#getChangedFiles()', function () {
var pluginMock;
let pluginMock;
before(function () {
pluginMock = {
compiler: compilerMock,
Expand All @@ -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',
Expand Down

0 comments on commit f6b3cfb

Please sign in to comment.