@@ -2,6 +2,234 @@ module.exports = {
2
2
'postcss-custom-media' : {
3
3
'basic' : {
4
4
message : 'supports basic usage'
5
+ } ,
6
+ 'basic:preserve' : {
7
+ message : 'supports { preserve: true } usage' ,
8
+ options : {
9
+ preserve : true
10
+ }
11
+ } ,
12
+ 'import' : {
13
+ message : 'supports { importFrom: { customMedia: { ... } } } usage' ,
14
+ options : {
15
+ importFrom : {
16
+ customMedia : {
17
+ '--mq-a' : '(max-width: 30em), (max-height: 30em)' ,
18
+ '--not-mq-a' : 'not all and (--mq-a)'
19
+ }
20
+ }
21
+ }
22
+ } ,
23
+ 'import:import-fn' : {
24
+ message : 'supports { importFrom() } usage' ,
25
+ options : {
26
+ importFrom ( ) {
27
+ return {
28
+ customMedia : {
29
+ '--mq-a' : '(max-width: 30em), (max-height: 30em)' ,
30
+ '--not-mq-a' : 'not all and (--mq-a)'
31
+ }
32
+ } ;
33
+ }
34
+ } ,
35
+ expect : 'import.expect.css' ,
36
+ result : 'import.result.css'
37
+ } ,
38
+ 'import:import-fn-promise' : {
39
+ message : 'supports { async importFrom() } usage' ,
40
+ options : {
41
+ importFrom ( ) {
42
+ return new Promise ( resolve => {
43
+ resolve ( {
44
+ customMedia : {
45
+ '--mq-a' : '(max-width: 30em), (max-height: 30em)' ,
46
+ '--not-mq-a' : 'not all and (--mq-a)'
47
+ }
48
+ } )
49
+ } ) ;
50
+ }
51
+ } ,
52
+ expect : 'import.expect.css' ,
53
+ result : 'import.result.css'
54
+ } ,
55
+ 'import:json' : {
56
+ message : 'supports { importFrom: "test/import-media.json" } usage' ,
57
+ options : {
58
+ importFrom : 'test/import-media.json'
59
+ } ,
60
+ expect : 'import.expect.css' ,
61
+ result : 'import.result.css'
62
+ } ,
63
+ 'import:js' : {
64
+ message : 'supports { importFrom: "test/import-media.js" } usage' ,
65
+ options : {
66
+ importFrom : 'test/import-media.js'
67
+ } ,
68
+ expect : 'import.expect.css' ,
69
+ result : 'import.result.css'
70
+ } ,
71
+ 'import:css' : {
72
+ message : 'supports { importFrom: "test/import-media.css" } usage' ,
73
+ options : {
74
+ importFrom : 'test/import-media.css'
75
+ } ,
76
+ expect : 'import.expect.css' ,
77
+ result : 'import.result.css'
78
+ } ,
79
+ 'import:css-from' : {
80
+ message : 'supports { importFrom: { from: "test/import-media.css" } } usage' ,
81
+ options : {
82
+ importFrom : { from : 'test/import-media.css' }
83
+ } ,
84
+ expect : 'import.expect.css' ,
85
+ result : 'import.result.css'
86
+ } ,
87
+ 'import:css-from-type' : {
88
+ message : 'supports { importFrom: [ { from: "test/import-media.css", type: "css" } ] } usage' ,
89
+ options : {
90
+ importFrom : [ { from : 'test/import-media.css' , type : 'css' } ]
91
+ } ,
92
+ expect : 'import.expect.css' ,
93
+ result : 'import.result.css'
94
+ } ,
95
+ 'basic:export' : {
96
+ message : 'supports { exportTo: { customMedia: { ... } } } usage' ,
97
+ options : {
98
+ exportTo : ( global . __exportMediaObject = global . __exportMediaObject || {
99
+ customMedia : null
100
+ } )
101
+ } ,
102
+ expect : 'basic.expect.css' ,
103
+ result : 'basic.result.css' ,
104
+ after ( ) {
105
+ if ( __exportMediaObject . customMedia [ '--mq-a' ] !== '(max-width: 30em), (max-height: 30em)' ) {
106
+ throw new Error ( 'The exportTo function failed' ) ;
107
+ }
108
+ }
109
+ } ,
110
+ 'basic:export-fn' : {
111
+ message : 'supports { exportTo() } usage' ,
112
+ options : {
113
+ exportTo ( customMedia ) {
114
+ if ( customMedia [ '--mq-a' ] !== '(max-width: 30em), (max-height: 30em)' ) {
115
+ throw new Error ( 'The exportTo function failed' ) ;
116
+ }
117
+ }
118
+ } ,
119
+ expect : 'basic.expect.css' ,
120
+ result : 'basic.result.css'
121
+ } ,
122
+ 'basic:export-fn-promise' : {
123
+ message : 'supports { async exportTo() } usage' ,
124
+ options : {
125
+ exportTo ( customMedia ) {
126
+ return new Promise ( ( resolve , reject ) => {
127
+ if ( customMedia [ '--mq-a' ] !== '(max-width: 30em), (max-height: 30em)' ) {
128
+ reject ( 'The exportTo function failed' ) ;
129
+ } else {
130
+ resolve ( ) ;
131
+ }
132
+ } ) ;
133
+ }
134
+ } ,
135
+ expect : 'basic.expect.css' ,
136
+ result : 'basic.result.css'
137
+ } ,
138
+ 'basic:export-json' : {
139
+ message : 'supports { exportTo: "test/export-media.json" } usage' ,
140
+ options : {
141
+ exportTo : 'test/export-media.json'
142
+ } ,
143
+ expect : 'basic.expect.css' ,
144
+ result : 'basic.result.css' ,
145
+ before ( ) {
146
+ global . __exportMediaString = require ( 'fs' ) . readFileSync ( 'test/export-media.json' , 'utf8' ) ;
147
+ } ,
148
+ after ( ) {
149
+ if ( global . __exportMediaString !== require ( 'fs' ) . readFileSync ( 'test/export-media.json' , 'utf8' ) ) {
150
+ throw new Error ( 'The original file did not match the freshly exported copy' ) ;
151
+ }
152
+ }
153
+ } ,
154
+ 'basic:export-js' : {
155
+ message : 'supports { exportTo: "test/export-media.js" } usage' ,
156
+ options : {
157
+ exportTo : 'test/export-media.js'
158
+ } ,
159
+ expect : 'basic.expect.css' ,
160
+ result : 'basic.result.css' ,
161
+ before ( ) {
162
+ global . __exportMediaString = require ( 'fs' ) . readFileSync ( 'test/export-media.js' , 'utf8' ) ;
163
+ } ,
164
+ after ( ) {
165
+ if ( global . __exportMediaString !== require ( 'fs' ) . readFileSync ( 'test/export-media.js' , 'utf8' ) ) {
166
+ throw new Error ( 'The original file did not match the freshly exported copy' ) ;
167
+ }
168
+ }
169
+ } ,
170
+ 'basic:export-mjs' : {
171
+ message : 'supports { exportTo: "test/export-media.mjs" } usage' ,
172
+ options : {
173
+ exportTo : 'test/export-media.mjs'
174
+ } ,
175
+ expect : 'basic.expect.css' ,
176
+ result : 'basic.result.css' ,
177
+ before ( ) {
178
+ global . __exportMediaString = require ( 'fs' ) . readFileSync ( 'test/export-media.mjs' , 'utf8' ) ;
179
+ } ,
180
+ after ( ) {
181
+ if ( global . __exportMediaString !== require ( 'fs' ) . readFileSync ( 'test/export-media.mjs' , 'utf8' ) ) {
182
+ throw new Error ( 'The original file did not match the freshly exported copy' ) ;
183
+ }
184
+ }
185
+ } ,
186
+ 'basic:export-css' : {
187
+ message : 'supports { exportTo: "test/export-media.css" } usage' ,
188
+ options : {
189
+ exportTo : 'test/export-media.css'
190
+ } ,
191
+ expect : 'basic.expect.css' ,
192
+ result : 'basic.result.css' ,
193
+ before ( ) {
194
+ global . __exportMediaString = require ( 'fs' ) . readFileSync ( 'test/export-media.css' , 'utf8' ) ;
195
+ } ,
196
+ after ( ) {
197
+ if ( global . __exportMediaString !== require ( 'fs' ) . readFileSync ( 'test/export-media.css' , 'utf8' ) ) {
198
+ throw new Error ( 'The original file did not match the freshly exported copy' ) ;
199
+ }
200
+ }
201
+ } ,
202
+ 'basic:export-css-to' : {
203
+ message : 'supports { exportTo: { to: "test/export-media.css" } } usage' ,
204
+ options : {
205
+ exportTo : { to : 'test/export-media.css' }
206
+ } ,
207
+ expect : 'basic.expect.css' ,
208
+ result : 'basic.result.css' ,
209
+ before ( ) {
210
+ global . __exportMediaString = require ( 'fs' ) . readFileSync ( 'test/export-media.css' , 'utf8' ) ;
211
+ } ,
212
+ after ( ) {
213
+ if ( global . __exportMediaString !== require ( 'fs' ) . readFileSync ( 'test/export-media.css' , 'utf8' ) ) {
214
+ throw new Error ( 'The original file did not match the freshly exported copy' ) ;
215
+ }
216
+ }
217
+ } ,
218
+ 'basic:export-css-to-type' : {
219
+ message : 'supports { exportTo: { to: "test/export-media.css", type: "css" } } usage' ,
220
+ options : {
221
+ exportTo : { to : 'test/export-media.css' , type : 'css' }
222
+ } ,
223
+ expect : 'basic.expect.css' ,
224
+ result : 'basic.result.css' ,
225
+ before ( ) {
226
+ global . __exportMediaString = require ( 'fs' ) . readFileSync ( 'test/export-media.css' , 'utf8' ) ;
227
+ } ,
228
+ after ( ) {
229
+ if ( global . __exportMediaString !== require ( 'fs' ) . readFileSync ( 'test/export-media.css' , 'utf8' ) ) {
230
+ throw new Error ( 'The original file did not match the freshly exported copy' ) ;
231
+ }
232
+ }
5
233
}
6
234
}
7
235
} ;
0 commit comments