@@ -4,17 +4,21 @@ var path = require('path');
44var mixins = require ( '../' ) ;
55
66function run ( input , output , opts ) {
7- return postcss ( [ mixins ( opts ) ] ) . process ( input ) . then ( result => {
8- expect ( result . css ) . toEqual ( output ) ;
9- expect ( result . warnings ( ) . length ) . toBe ( 0 ) ;
10- return result ;
11- } ) ;
7+ return postcss ( [ mixins ( opts ) ] )
8+ . process ( input , { from : undefined } )
9+ . then ( result => {
10+ expect ( result . css ) . toEqual ( output ) ;
11+ expect ( result . warnings ( ) . length ) . toBe ( 0 ) ;
12+ return result ;
13+ } ) ;
1214}
1315
1416it ( 'throws error on unknown mixin' , ( ) => {
15- return postcss ( mixins ) . process ( '@mixin A' ) . catch ( err => {
16- expect ( err . reason ) . toEqual ( 'Undefined mixin A' ) ;
17- } ) ;
17+ return postcss ( mixins )
18+ . process ( '@mixin A' , { from : undefined } )
19+ . catch ( err => {
20+ expect ( err . reason ) . toEqual ( 'Undefined mixin A' ) ;
21+ } ) ;
1822} ) ;
1923
2024it ( 'cans remove unknown mixin on request' , ( ) => {
@@ -106,10 +110,12 @@ it('throws on unknown mixin type', done => {
106110 a : 1
107111 }
108112 } ;
109- return postcss ( [ mixins ( opts ) ] ) . process ( '@mixin a' ) . catch ( e => {
110- expect ( e . message ) . toEqual ( 'Wrong a mixin type number' ) ;
111- done ( ) ;
112- } ) ;
113+ return postcss ( [ mixins ( opts ) ] )
114+ . process ( '@mixin a' , { from : undefined } )
115+ . catch ( e => {
116+ expect ( e . message ) . toEqual ( 'Wrong a mixin type number' ) ;
117+ done ( ) ;
118+ } ) ;
113119} ) ;
114120
115121it ( 'supports CSS mixins' , ( ) => {
@@ -234,33 +240,39 @@ it('loads mixins from dir with parent options', () => {
234240 parent : path . join ( __dirname , 'a.js' )
235241 }
236242 ) . then ( result => {
237- expect ( result . messages ) . toEqual ( [
238- {
239- file : path . join ( __dirname , 'mixins/a.js' ) ,
240- type : 'dependency' ,
241- parent : parent
242- } ,
243- {
244- file : path . join ( __dirname , 'mixins/b.json' ) ,
245- type : 'dependency' ,
246- parent : parent
247- } ,
248- {
249- file : path . join ( __dirname , 'mixins/c.CSS' ) ,
250- type : 'dependency' ,
251- parent : parent
252- } ,
253- {
254- file : path . join ( __dirname , 'mixins/d.sss' ) ,
255- type : 'dependency' ,
256- parent : parent
257- } ,
258- {
259- file : path . join ( __dirname , 'mixins/e.pcss' ) ,
260- type : 'dependency' ,
261- parent : parent
262- }
263- ] ) ;
243+ // Array could have files sorted in non-alphabetical order.
244+ // Check array length, and that it contains all required items,
245+ // regardless they order within array.
246+ expect ( result . messages ) . toHaveLength ( 5 ) ;
247+ expect ( result . messages ) . toEqual (
248+ expect . arrayContaining ( [
249+ {
250+ file : path . join ( __dirname , 'mixins/a.js' ) ,
251+ type : 'dependency' ,
252+ parent : parent
253+ } ,
254+ {
255+ file : path . join ( __dirname , 'mixins/b.json' ) ,
256+ type : 'dependency' ,
257+ parent : parent
258+ } ,
259+ {
260+ file : path . join ( __dirname , 'mixins/c.CSS' ) ,
261+ type : 'dependency' ,
262+ parent : parent
263+ } ,
264+ {
265+ file : path . join ( __dirname , 'mixins/d.sss' ) ,
266+ type : 'dependency' ,
267+ parent : parent
268+ } ,
269+ {
270+ file : path . join ( __dirname , 'mixins/e.pcss' ) ,
271+ type : 'dependency' ,
272+ parent : parent
273+ }
274+ ] )
275+ ) ;
264276 } ) ;
265277} ) ;
266278
@@ -313,9 +325,11 @@ it('coverts mixins values', () => {
313325 }
314326 }
315327 } ) ) ;
316- return proccessor . process ( 'a{ @mixin empty; }' ) . then ( result => {
317- expect ( typeof result . root . first . first . value ) . toEqual ( 'string' ) ;
318- } ) ;
328+ return proccessor
329+ . process ( 'a{ @mixin empty; }' , { from : undefined } )
330+ . then ( result => {
331+ expect ( typeof result . root . first . first . value ) . toEqual ( 'string' ) ;
332+ } ) ;
319333} ) ;
320334
321335it ( 'supports nested mixins' , ( ) => {
@@ -358,7 +372,9 @@ it('supports default arguments in nested mixins', () => {
358372it ( 'works in sync mode on no option' , ( ) => {
359373 var input = '@define-mixin a { a: 1 }; @mixin a' ;
360374 var output = 'a: 1' ;
361- expect ( postcss ( mixins ( ) ) . process ( input ) . css ) . toEqual ( output ) ;
375+ expect (
376+ postcss ( mixins ( ) ) . process ( input , { from : undefined } ) . css
377+ ) . toEqual ( output ) ;
362378} ) ;
363379
364380it ( 'cans remove unknown mixin on request' , ( ) => {
0 commit comments