1- /* eslint no-unused-expressions: 0 */
2-
31'use strict' ;
42
53var assign = require ( 'object-assign' ) ;
6- var webpack = require ( 'webpack' ) ;
7- var MemoryFileSystem = require ( 'memory-fs' ) ;
84
9- var StyleLintPlugin = require ( getPath ( '../index' ) ) ;
10- var outputFileSystem = new MemoryFileSystem ( ) ;
5+ var StyleLintPlugin = require ( '../' ) ;
6+ var pack = require ( './helpers/pack' ) ;
117
128var configFilePath = getPath ( './.stylelintrc' ) ;
139var baseConfig = {
@@ -23,48 +19,33 @@ var baseConfig = {
2319 ]
2420} ;
2521
26- // This is the basic in-memory compiler
27- function pack ( testConfig , callback ) {
28- var compiler = webpack ( testConfig ) ;
29- compiler . outputFileSystem = outputFileSystem ;
30- compiler . run ( callback ) ;
31- }
32-
3322describe ( 'stylelint-webpack-plugin' , function ( ) {
34- it ( 'works with a simple file' , function ( done ) {
23+ it ( 'works with a simple file' , function ( ) {
3524 var config = {
3625 context : './test/fixtures/test1' ,
3726 entry : './index'
3827 } ;
3928
40- pack ( assign ( { } , baseConfig , config ) , function ( err , stats ) {
41- expect ( err ) . to . not . exist ;
42- expect ( stats . compilation . errors ) . to . have . length ( 0 ) ;
43- expect ( stats . compilation . warnings ) . to . have . length ( 0 ) ;
44- done ( err ) ;
45- } ) ;
29+ return pack ( assign ( { } , baseConfig , config ) )
30+ . then ( function ( stats ) {
31+ expect ( stats . compilation . errors ) . to . have . length ( 0 ) ;
32+ expect ( stats . compilation . warnings ) . to . have . length ( 0 ) ;
33+ } ) ;
4634 } ) ;
4735
48- it ( 'sends errors properly' , function ( done ) {
36+ it ( 'sends errors properly' , function ( ) {
4937 var config = {
5038 context : './test/fixtures/test3' ,
51- entry : './index' ,
52- plugins : [
53- new StyleLintPlugin ( {
54- quiet : true ,
55- configFile : configFilePath
56- } )
57- ]
39+ entry : './index'
5840 } ;
5941
60- pack ( assign ( { } , baseConfig , config ) , function ( err , stats ) {
61- expect ( err ) . to . not . exist ;
62- expect ( stats . compilation . errors ) . to . have . length ( 1 ) ;
63- done ( err ) ;
64- } ) ;
42+ return pack ( assign ( { } , baseConfig , config ) )
43+ . then ( function ( stats ) {
44+ expect ( stats . compilation . errors ) . to . have . length ( 1 ) ;
45+ } ) ;
6546 } ) ;
6647
67- it ( 'fails on errors' , function ( ) {
48+ it ( 'fails on errors when asked to ' , function ( ) {
6849 var config = {
6950 context : './test/fixtures/test3' ,
7051 entry : './index' ,
@@ -77,62 +58,19 @@ describe('stylelint-webpack-plugin', function () {
7758 ]
7859 } ;
7960
80- return expect ( new Promise ( function ( resolve , reject ) {
81- var compiler = webpack ( assign ( { } , baseConfig , config ) ) ;
82- compiler . outputFileSystem = outputFileSystem ;
83- compiler . run ( function ( err ) {
84- reject ( err ) ;
85- } ) ;
86- } ) ) . to . eventually . be . rejectedWith ( 'Error: Failed because of a stylelint error.\n' ) ;
87- } ) ;
88-
89- it ( 'can specify a JSON config file via config' , function ( done ) {
90- var config = {
91- context : './test/fixtures/test5' ,
92- entry : './index' ,
93- plugins : [
94- new StyleLintPlugin ( {
95- configFile : configFilePath ,
96- quiet : true
97- } )
98- ]
99- } ;
100-
101- pack ( assign ( { } , baseConfig , config ) , function ( err , stats ) {
102- expect ( err ) . to . not . exist ;
103- expect ( stats . compilation . errors ) . to . have . length ( 0 ) ;
104- done ( err ) ;
105- } ) ;
61+ expect ( pack ( assign ( { } , baseConfig , config ) ) )
62+ . to . eventually . be . rejectedWith ( 'Error: Failed because of a stylelint error.\n' ) ;
10663 } ) ;
10764
108- it ( 'works with multiple source files' , function ( done ) {
65+ it ( 'works with multiple source files' , function ( ) {
10966 var config = {
11067 context : './test/fixtures/test7' ,
11168 entry : './index'
11269 } ;
11370
114- pack ( assign ( { } , baseConfig , config ) , function ( err , stats ) {
115- expect ( err ) . to . not . exist ;
116- expect ( stats . compilation . errors ) . to . have . length ( 2 ) ;
117- done ( err ) ;
118- } ) ;
71+ return pack ( assign ( { } , baseConfig , config ) )
72+ . then ( function ( stats ) {
73+ expect ( stats . compilation . errors ) . to . have . length ( 2 ) ;
74+ } ) ;
11975 } ) ;
120-
121- // it('should work with multiple context', function(done) {
122- // var config = {
123- // context: './test/fixtures/test5',
124- // entry: './index',
125- // plugins: [ new StyleLintPlugin({
126- // configFile: configFilePath,
127- // context: ['./test/testFiles/test5', './test/testFiles/test7']
128- // })]
129- // };
130-
131- // pack(assign({}, baseConfig, config), function (err, stats) {
132- // expect(err).to.not.exist;
133- // expect(stats.compilation.errors.length).to.equal(0);
134- // expect(stats.compilation.warnings.length).not.to.equal(0);
135- // done(err);
136- // });
137- // });
13876} ) ;
0 commit comments