11'use strict' ;
22
33var assign = require ( 'object-assign' ) ;
4+ var td = require ( 'testdouble' ) ;
45var StyleLintPlugin = require ( '../' ) ;
56var pack = require ( './helpers/pack' ) ;
67var webpack = require ( './helpers/webpack' ) ;
78var baseConfig = require ( './helpers/base-config' ) ;
89
910var configFilePath = getPath ( './.stylelintrc' ) ;
11+ var errorMessage = require ( '../lib/constants' ) . errorMessage ;
1012
1113describe ( 'stylelint-webpack-plugin' , function ( ) {
1214 it ( 'works with a simple file' , function ( ) {
@@ -51,7 +53,7 @@ describe('stylelint-webpack-plugin', function () {
5153 return pack ( assign ( { } , baseConfig , config ) )
5254 . then ( expect . fail )
5355 . catch ( function ( err ) {
54- expect ( err . message ) . to . equal ( 'Failed because of a stylelint error.\n' ) ;
56+ expect ( err . message ) . to . equal ( errorMessage ) ;
5557 } ) ;
5658 } ) ;
5759
@@ -82,26 +84,6 @@ describe('stylelint-webpack-plugin', function () {
8284 } ) ;
8385 } ) ;
8486
85- // TODO use snapshots to ensure something is printed to the console
86- it . skip ( 'sends messages to console when quiet prop set to false' , function ( ) {
87- var config = {
88- context : './test/fixtures/syntax-error' ,
89- entry : './index' ,
90- plugins : [
91- new StyleLintPlugin ( {
92- configFile : configFilePath ,
93- quiet : true
94- } )
95- ]
96- } ;
97-
98- return pack ( assign ( { } , baseConfig , config ) )
99- . then ( function ( stats ) {
100- expect ( stats . compilation . errors ) . to . have . length ( 1 ) ;
101- expect ( stats . compilation . warnings ) . to . have . length ( 0 ) ;
102- } ) ;
103- } ) ;
104-
10587 it ( 'fails when .stylelintrc is not a proper format' , function ( ) {
10688 var config = {
10789 entry : './index' ,
@@ -121,6 +103,35 @@ describe('stylelint-webpack-plugin', function () {
121103 } ) ;
122104 } ) ;
123105
106+ context ( 'iff quiet is strictly false' , function ( ) {
107+ beforeEach ( function ( ) {
108+ td . replace ( console , 'warn' , td . function ( ) ) ;
109+ } ) ;
110+
111+ afterEach ( function ( ) {
112+ td . reset ( ) ;
113+ } ) ;
114+
115+ it ( 'sends messages to the console' , function ( ) {
116+ var config = {
117+ context : './test/fixtures/syntax-error' ,
118+ entry : './index' ,
119+ plugins : [
120+ new StyleLintPlugin ( {
121+ configFile : configFilePath ,
122+ quiet : false
123+ } )
124+ ]
125+ } ;
126+
127+ return pack ( assign ( { } , baseConfig , config ) )
128+ . then ( function ( stats ) {
129+ expect ( stats . compilation . errors ) . to . have . length ( 1 ) ;
130+ td . verify ( console . warn ( td . matchers . contains ( '✖' ) ) ) ;
131+ } ) ;
132+ } ) ;
133+ } ) ;
134+
124135 context ( 'without StyleLintPlugin configuration' , function ( ) {
125136 var config = {
126137 context : './test/fixtures/lint-free' ,
0 commit comments