@@ -93,11 +93,9 @@ it('should respond with error on stream files', function (cb) {
9393} )
9494
9595
96- it ( 'should throw error if processors are not provided' , function ( cb ) {
97- assert . throws ( function ( ) { postcss ( ) } , gutil . PluginError )
96+ it ( 'should throw error if plugins are not array' , function ( ) {
9897 assert . throws ( function ( ) { postcss ( '' ) } , gutil . PluginError )
9998 assert . throws ( function ( ) { postcss ( { } ) } , gutil . PluginError )
100- cb ( )
10199} )
102100
103101
@@ -171,13 +169,22 @@ describe('PostCSS Guidelines', function () {
171169 use : function ( ) { }
172170 , process : function ( ) { }
173171 }
172+ var postcssLoadConfigStub
174173 var postcss = proxyquire ( './index' , {
175- postcss : function ( ) {
174+ postcss : function ( plugins ) {
175+ postcssStub . use ( plugins )
176176 return postcssStub
177177 }
178+ , 'postcss-load-config' : function ( args ) {
179+ return postcssLoadConfigStub ( args )
180+ }
181+ , 'vinyl-sourcemaps-apply' : function ( ) {
182+ return { }
183+ }
178184 } )
179185
180186 beforeEach ( function ( ) {
187+ postcssLoadConfigStub = sandbox . stub ( )
181188 sandbox . stub ( postcssStub , 'use' )
182189 sandbox . stub ( postcssStub , 'process' )
183190 } )
@@ -186,7 +193,6 @@ describe('PostCSS Guidelines', function () {
186193 sandbox . restore ( )
187194 } )
188195
189-
190196 it ( 'should set `from` and `to` processing options to `file.path`' , function ( cb ) {
191197
192198 var stream = postcss ( [ doubler ] )
@@ -236,6 +242,82 @@ describe('PostCSS Guidelines', function () {
236242
237243 } )
238244
245+ it ( 'should take plugins and options from postcss-load-config' , function ( cb ) {
246+
247+ var cssPath = __dirname + '/fixture.css'
248+ var stream = postcss ( )
249+ var plugins = [ doubler ]
250+
251+ postcssLoadConfigStub . returns ( Promise . resolve ( {
252+ plugins : plugins
253+ , options : { to : 'overriden' }
254+ } ) )
255+
256+ postcssStub . process . returns ( Promise . resolve ( {
257+ css : ''
258+ , warnings : function ( ) {
259+ return [ ]
260+ }
261+ } ) )
262+
263+ stream . on ( 'data' , function ( ) {
264+ assert . deepEqual ( postcssLoadConfigStub . getCall ( 0 ) . args [ 0 ] , {
265+ from : cssPath
266+ , to : cssPath
267+ , map : false
268+ } )
269+ assert . equal ( postcssStub . use . getCall ( 0 ) . args [ 0 ] , plugins )
270+ assert . equal ( postcssStub . process . getCall ( 0 ) . args [ 1 ] . to , 'overriden' )
271+ cb ( )
272+ } )
273+
274+ stream . write ( new gutil . File ( {
275+ contents : new Buffer ( 'a {}' )
276+ , path : cssPath
277+ } ) )
278+
279+ stream . end ( )
280+
281+ } )
282+
283+ it ( 'should not override `from` and `map` if using source maps' , function ( cb ) {
284+ var stream = postcss ( [ doubler ] , { from : 'overriden' , map : 'overriden' } )
285+ var cssPath = __dirname + '/fixture.css'
286+ postcssStub . process . returns ( Promise . resolve ( {
287+ css : ''
288+ , warnings : function ( ) {
289+ return [ ]
290+ }
291+ , map : {
292+ toJSON : function ( ) {
293+ return {
294+ sources : [ ] ,
295+ file : ''
296+ }
297+ }
298+ }
299+ } ) )
300+
301+ sandbox . stub ( gutil , 'log' )
302+
303+ stream . on ( 'data' , function ( ) {
304+ assert . deepEqual ( postcssStub . process . getCall ( 0 ) . args [ 1 ] . from , cssPath )
305+ assert . deepEqual ( postcssStub . process . getCall ( 0 ) . args [ 1 ] . map , { annotation : false } )
306+ var firstMessage = gutil . log . getCall ( 0 ) . args [ 1 ]
307+ var secondMessage = gutil . log . getCall ( 1 ) . args [ 1 ]
308+ assert ( firstMessage , '/fixture.css\nCannot override from option, because it is required by gulp-sourcemap' )
309+ assert ( secondMessage , '/fixture.css\nCannot override map option, because it is required by gulp-sourcemap' )
310+ cb ( )
311+ } )
312+
313+ var file = new gutil . File ( {
314+ contents : new Buffer ( 'a {}' )
315+ , path : cssPath
316+ } )
317+ file . sourceMap = { }
318+ stream . end ( file )
319+ } )
320+
239321 it ( 'should not output js stack trace for `CssSyntaxError`' , function ( cb ) {
240322
241323 var stream = postcss ( [ doubler ] )
0 commit comments