@@ -12,96 +12,93 @@ const loaderContext = {
12
12
13
13
describe ( 'autoload config' , ( ) => {
14
14
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 (
26
16
loaderContext ,
27
17
path . resolve ( testDirectory , 'rc' )
28
18
) ;
29
19
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
+ ) ;
31
27
} ) ;
32
28
33
29
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 (
47
31
loaderContext ,
48
32
path . resolve ( testDirectory , 'pkg' )
49
33
) ;
50
34
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
+ ) ;
52
44
} ) ;
53
45
54
46
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 (
70
48
loaderContext ,
71
49
path . resolve ( testDirectory , 'js/object' )
72
50
) ;
73
51
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
+ ) ;
75
63
} ) ;
76
64
77
65
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 (
93
67
loaderContext ,
94
68
path . resolve ( testDirectory , 'js/array' )
95
69
) ;
96
70
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
+ ) ;
98
95
} ) ;
99
96
100
97
it ( 'should throw an error on "unresolved" config' , async ( ) => {
101
98
try {
102
99
await loadConfig ( loaderContext , path . resolve ( 'unresolved' ) ) ;
103
100
} 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 : ( .* ) $ / ) ;
105
102
}
106
103
} ) ;
107
104
} ) ;
0 commit comments