11import _webpack from 'webpack' ;
22import ExtractTextPlugin from 'extract-text-webpack-plugin' ;
3+ import OptimizeCssPlugin from 'optimize-css-assets-webpack-plugin' ;
34import CSSSplitWebpackPlugin from '../../src' ;
45import path from 'path' ;
56import MemoryFileSystem from 'memory-fs' ;
@@ -17,7 +18,10 @@ const extract = ExtractTextPlugin.extract.length !== 1 ?
1718 loader : fallbackLoader ,
1819 } ) ;
1920
20- const config = ( options , entry = basic , extra ) => {
21+ const config = ( options , entry = basic , {
22+ plugins,
23+ ...extra
24+ } = { devtool : 'source-map' } ) => {
2125 return {
2226 entry : path . join ( __dirname , '..' , '..' , 'example' , entry ) ,
2327 context : path . join ( __dirname , '..' , '..' , 'example' ) ,
@@ -40,10 +44,10 @@ const config = (options, entry = basic, extra) => {
4044 ) ,
4145 } ] ,
4246 } ,
43- devtool : 'source-map' ,
4447 plugins : [
4548 new ExtractTextPlugin ( 'styles.css' ) ,
4649 new CSSSplitWebpackPlugin ( options ) ,
50+ ...( plugins || [ ] ) ,
4751 ] ,
4852 ...extra ,
4953 } ;
@@ -139,7 +143,7 @@ describe('CSSSplitWebpackPlugin', () => {
139143 ) . to . throw ( TypeError ) ;
140144 } ) ;
141145 describe ( 'deferred emit' , ( ) => {
142- it ( 'should split css files when necessary' , ( done ) => {
146+ it ( 'should split css files when necessary' , ( ) =>
143147 webpack ( { size : 3 , defer : true } ) . then ( ( { stats, files} ) => {
144148 expect ( stats . assetsByChunkName )
145149 . to . have . property ( 'main' )
@@ -148,10 +152,9 @@ describe('CSSSplitWebpackPlugin', () => {
148152 expect ( files ) . to . have . property ( 'styles-1.css' ) ;
149153 expect ( files ) . to . have . property ( 'styles-2.css' ) ;
150154 expect ( files ) . to . have . property ( 'styles.css.map' ) ;
151- done ( ) ;
152- } ) ;
153- } ) ;
154- it ( 'should ignore files that do not need splitting' , ( done ) => {
155+ } )
156+ ) ;
157+ it ( 'should ignore files that do not need splitting' , ( ) =>
155158 webpack ( { size : 10 , defer : true } ) . then ( ( { stats, files} ) => {
156159 expect ( stats . assetsByChunkName )
157160 . to . have . property ( 'main' )
@@ -161,8 +164,23 @@ describe('CSSSplitWebpackPlugin', () => {
161164 expect ( files ) . to . have . property ( 'styles.css' ) ;
162165 expect ( files ) . to . not . have . property ( 'styles-1.css' ) ;
163166 expect ( files ) . to . not . have . property ( 'styles-2.css' ) ;
164- done ( ) ;
165- } ) ;
166- } ) ;
167+ } )
168+ ) ;
169+ it ( 'should handle cases when there are no source maps' , ( ) =>
170+ webpack ( {
171+ size : 3 ,
172+ defer : true ,
173+ } , basic , {
174+ devtool : null ,
175+ plugins : [
176+ new OptimizeCssPlugin ( ) ,
177+ ] ,
178+ } ) . then ( ( { stats, files} ) => {
179+ expect ( files ) . to . not . have . property ( 'styles-1.css.map' ) ;
180+ expect ( stats . assetsByChunkName )
181+ . to . have . property ( 'main' )
182+ . to . contain ( 'styles-1.css' ) ;
183+ } )
184+ ) ;
167185 } ) ;
168186} ) ;
0 commit comments