@@ -12,96 +12,93 @@ const loaderContext = {
1212
1313describe ( 'autoload config' , ( ) => {
1414 it ( 'should load ".postcssrc"' , async ( ) => {
15- const expected = ( config ) => {
16- expect ( config . map ) . toEqual ( false ) ;
17- expect ( config . from ) . toEqual ( './test/rc/fixtures/index.css' ) ;
18- expect ( config . to ) . toEqual ( './test/rc/expect/index.css' ) ;
19- expect ( Object . keys ( config . plugins ) . length ) . toEqual ( 2 ) ;
20- expect ( config . file ) . toEqual (
21- path . resolve ( testDirectory , 'rc' , '.postcssrc' )
22- ) ;
23- } ;
24-
25- const config = await loadConfig (
15+ const loadedConfig = await loadConfig (
2616 loaderContext ,
2717 path . resolve ( testDirectory , 'rc' )
2818 ) ;
2919
30- expected ( config ) ;
20+ expect ( loadedConfig . config . map ) . toEqual ( false ) ;
21+ expect ( loadedConfig . config . from ) . toEqual ( './test/rc/fixtures/index.css' ) ;
22+ expect ( loadedConfig . config . to ) . toEqual ( './test/rc/expect/index.css' ) ;
23+ expect ( Object . keys ( loadedConfig . config . plugins ) . length ) . toEqual ( 2 ) ;
24+ expect ( loadedConfig . filepath ) . toEqual (
25+ path . resolve ( testDirectory , 'rc' , '.postcssrc' )
26+ ) ;
3127 } ) ;
3228
3329 it ( 'should load "package.json"' , async ( ) => {
34- const expected = ( config ) => {
35- expect ( config . parser ) . toEqual ( false ) ;
36- expect ( config . syntax ) . toEqual ( false ) ;
37- expect ( config . map ) . toEqual ( false ) ;
38- expect ( config . from ) . toEqual ( './index.css' ) ;
39- expect ( config . to ) . toEqual ( './index.css' ) ;
40- expect ( Object . keys ( config . plugins ) . length ) . toEqual ( 2 ) ;
41- expect ( config . file ) . toEqual (
42- path . resolve ( testDirectory , 'pkg' , 'package.json' )
43- ) ;
44- } ;
45-
46- const config = await loadConfig (
30+ const loadedConfig = await loadConfig (
4731 loaderContext ,
4832 path . resolve ( testDirectory , 'pkg' )
4933 ) ;
5034
51- expected ( config ) ;
35+ expect ( loadedConfig . config . parser ) . toEqual ( false ) ;
36+ expect ( loadedConfig . config . syntax ) . toEqual ( false ) ;
37+ expect ( loadedConfig . config . map ) . toEqual ( false ) ;
38+ expect ( loadedConfig . config . from ) . toEqual ( './index.css' ) ;
39+ expect ( loadedConfig . config . to ) . toEqual ( './index.css' ) ;
40+ expect ( Object . keys ( loadedConfig . config . plugins ) . length ) . toEqual ( 2 ) ;
41+ expect ( loadedConfig . filepath ) . toEqual (
42+ path . resolve ( testDirectory , 'pkg' , 'package.json' )
43+ ) ;
5244 } ) ;
5345
5446 it ( 'should load "postcss.config.js" with "Object" syntax of plugins' , async ( ) => {
55- const expected = ( config ) => {
56- expect ( config . map ) . toEqual ( false ) ;
57- expect ( config . from ) . toEqual (
58- './test/fixtures/config-autoload/js/object/index.css'
59- ) ;
60- expect ( config . to ) . toEqual (
61- './test/fixtures/config-autoload/js/object/expect/index.css'
62- ) ;
63- expect ( Object . keys ( config . plugins ) . length ) . toEqual ( 2 ) ;
64- expect ( config . file ) . toEqual (
65- path . resolve ( testDirectory , 'js/object' , 'postcss.config.js' )
66- ) ;
67- } ;
68-
69- const config = await loadConfig (
47+ const loadedConfig = await loadConfig (
7048 loaderContext ,
7149 path . resolve ( testDirectory , 'js/object' )
7250 ) ;
7351
74- expected ( config ) ;
52+ expect ( loadedConfig . config . map ) . toEqual ( false ) ;
53+ expect ( loadedConfig . config . from ) . toEqual (
54+ './test/fixtures/config-autoload/js/object/index.css'
55+ ) ;
56+ expect ( loadedConfig . config . to ) . toEqual (
57+ './test/fixtures/config-autoload/js/object/expect/index.css'
58+ ) ;
59+ expect ( Object . keys ( loadedConfig . config . plugins ) . length ) . toEqual ( 2 ) ;
60+ expect ( loadedConfig . filepath ) . toEqual (
61+ path . resolve ( testDirectory , 'js/object' , 'postcss.config.js' )
62+ ) ;
7563 } ) ;
7664
7765 it ( 'should load "postcss.config.js" with "Array" syntax of plugins' , async ( ) => {
78- const expected = ( config ) => {
79- expect ( config . map ) . toEqual ( false ) ;
80- expect ( config . from ) . toEqual (
81- './test/fixtures/config-autoload/js/object/index.css'
82- ) ;
83- expect ( config . to ) . toEqual (
84- './test/fixtures/config-autoload/js/object/expect/index.css'
85- ) ;
86- expect ( Object . keys ( config . plugins ) . length ) . toEqual ( 2 ) ;
87- expect ( config . file ) . toEqual (
88- path . resolve ( testDirectory , 'js/array' , 'postcss.config.js' )
89- ) ;
90- } ;
91-
92- const config = await loadConfig (
66+ const loadedConfig = await loadConfig (
9367 loaderContext ,
9468 path . resolve ( testDirectory , 'js/array' )
9569 ) ;
9670
97- expected ( config ) ;
71+ expect ( loadedConfig . config . map ) . toEqual ( false ) ;
72+ expect ( loadedConfig . config . from ) . toEqual (
73+ './test/fixtures/config-autoload/js/object/index.css'
74+ ) ;
75+ expect ( loadedConfig . config . to ) . toEqual (
76+ './test/fixtures/config-autoload/js/object/expect/index.css'
77+ ) ;
78+ expect ( Object . keys ( loadedConfig . config . plugins ) . length ) . toEqual ( 2 ) ;
79+ expect ( loadedConfig . filepath ) . toEqual (
80+ path . resolve ( testDirectory , 'js/array' , 'postcss.config.js' )
81+ ) ;
82+ } ) ;
83+
84+ it ( 'should load empty ".postcssrc"' , async ( ) => {
85+ const loadedConfig = await loadConfig (
86+ loaderContext ,
87+ path . resolve ( testDirectory , 'empty/.postcssrc' )
88+ ) ;
89+
90+ // eslint-disable-next-line no-undefined
91+ expect ( loadedConfig . config ) . toEqual ( undefined ) ;
92+ expect ( loadedConfig . filepath ) . toEqual (
93+ path . resolve ( testDirectory , 'empty/.postcssrc' )
94+ ) ;
9895 } ) ;
9996
10097 it ( 'should throw an error on "unresolved" config' , async ( ) => {
10198 try {
10299 await loadConfig ( loaderContext , path . resolve ( 'unresolved' ) ) ;
103100 } catch ( error ) {
104- expect ( error . message ) . toMatch ( / ^ N o P o s t C S S C o n f i g f o u n d i n : ( .* ) $ / ) ;
101+ expect ( error . message ) . toMatch ( / ^ N o P o s t C S S c o n f i g f o u n d i n : ( .* ) $ / ) ;
105102 }
106103 } ) ;
107104} ) ;
0 commit comments