@@ -9,12 +9,23 @@ const compile = input => postcss([plugin]).process(strip(input));
9
9
10
10
const getWarnings = result => result . warnings ( ) . map ( warning => warning . text ) ;
11
11
12
- const run = ( { fixture, expected, warnings = [ ] } ) =>
12
+ const getMessages = result =>
13
+ result . messages . filter ( msg => msg . type !== "warning" ) ;
14
+
15
+ const run = ( { fixture, expected, warnings = [ ] , messages = [ ] } ) =>
13
16
compile ( fixture ) . then ( result => {
14
- expect ( getWarnings ( result ) ) . toEqual ( warnings ) ;
15
17
expect ( result . css . trim ( ) ) . toEqual ( strip ( expected ) ) ;
18
+ expect ( getWarnings ( result ) ) . toEqual ( warnings ) ;
19
+ expect ( getMessages ( result ) ) . toEqual ( messages ) ;
16
20
} ) ;
17
21
22
+ const getMsg = ( name , value ) => ( {
23
+ plugin : "postcss-icss-values" ,
24
+ type : "icss-value" ,
25
+ name,
26
+ value
27
+ } ) ;
28
+
18
29
test ( "export value" , ( ) => {
19
30
return run ( {
20
31
fixture : `
@@ -26,7 +37,11 @@ test("export value", () => {
26
37
red: 1px solid #f00;
27
38
blue: 1px solid #00f
28
39
}
29
- `
40
+ ` ,
41
+ messages : [
42
+ getMsg ( "red" , "1px solid #f00" ) ,
43
+ getMsg ( "blue" , "1px solid #00f" )
44
+ ]
30
45
} ) ;
31
46
} ) ;
32
47
@@ -56,7 +71,8 @@ test("replace values within the file", () => {
56
71
@media red {
57
72
.red { color: red }
58
73
}
59
- `
74
+ ` ,
75
+ messages : [ getMsg ( "blue" , "red" ) ]
60
76
} ) ;
61
77
} ) ;
62
78
@@ -74,7 +90,8 @@ test("import external values", () => {
74
90
red: __value__red__0
75
91
}
76
92
.foo { color: __value__red__0 }
77
- `
93
+ ` ,
94
+ messages : [ getMsg ( "red" , "__value__red__0" ) ]
78
95
} ) ;
79
96
} ) ;
80
97
@@ -99,7 +116,13 @@ test("import multiple external values", () => {
99
116
green: __value__green__2;
100
117
yellow: __value__yellow__3
101
118
}
102
- `
119
+ ` ,
120
+ messages : [
121
+ getMsg ( "red" , "__value__red__0" ) ,
122
+ getMsg ( "blue" , "__value__blue__1" ) ,
123
+ getMsg ( "green" , "__value__green__2" ) ,
124
+ getMsg ( "yellow" , "__value__yellow__3" )
125
+ ]
103
126
} ) ;
104
127
} ) ;
105
128
@@ -119,7 +142,11 @@ test("import external values with aliases", () => {
119
142
blue1: __value__blue1__1
120
143
}
121
144
.foo { color: __value__red1__0; background: blue }
122
- `
145
+ ` ,
146
+ messages : [
147
+ getMsg ( "red1" , "__value__red1__0" ) ,
148
+ getMsg ( "blue1" , "__value__blue1__1" )
149
+ ]
123
150
} ) ;
124
151
} ) ;
125
152
@@ -144,7 +171,11 @@ test("import multiple values grouped with parentheses on multiple lines", () =>
144
171
}
145
172
.foo { color: __value__red__1; }
146
173
.bar { color: __value__blue__0 }
147
- `
174
+ ` ,
175
+ messages : [
176
+ getMsg ( "blue" , "__value__blue__0" ) ,
177
+ getMsg ( "red" , "__value__red__1" )
178
+ ]
148
179
} ) ;
149
180
} ) ;
150
181
@@ -191,7 +222,8 @@ test("allow transitive values", () => {
191
222
bbb: red;
192
223
}
193
224
.a { color: red; }
194
- `
225
+ ` ,
226
+ messages : [ getMsg ( "aaa" , "red" ) , getMsg ( "bbb" , "red" ) ]
195
227
} ) ;
196
228
} ) ;
197
229
@@ -208,7 +240,8 @@ test("allow transitive values within calc", () => {
208
240
large: calc(10px * 2);
209
241
}
210
242
.a { margin: calc(10px * 2); }
211
- `
243
+ ` ,
244
+ messages : [ getMsg ( "base" , "10px" ) , getMsg ( "large" , "calc(10px * 2)" ) ]
212
245
} ) ;
213
246
} ) ;
214
247
@@ -225,7 +258,8 @@ test("allow custom-property-style names", () => {
225
258
--red: __value____red__0;
226
259
}
227
260
.foo { color: __value____red__0; }
228
- `
261
+ ` ,
262
+ messages : [ getMsg ( "--red" , "__value____red__0" ) ]
229
263
} ) ;
230
264
} ) ;
231
265
@@ -260,7 +294,14 @@ test("allow all colour types", () => {
260
294
border-bottom-color: rgba(34, 12, 64, 0.3);
261
295
outline-color: hsla(220, 13.0%, 18.0%, 1);
262
296
}
263
- `
297
+ ` ,
298
+ messages : [
299
+ getMsg ( "named" , "red" ) ,
300
+ getMsg ( "3char" , "#0f0" ) ,
301
+ getMsg ( "6char" , "#00ff00" ) ,
302
+ getMsg ( "rgba" , "rgba(34, 12, 64, 0.3)" ) ,
303
+ getMsg ( "hsla" , "hsla(220, 13.0%, 18.0%, 1)" )
304
+ ]
264
305
} ) ;
265
306
} ) ;
266
307
@@ -275,7 +316,13 @@ test("allow definitions with commas in them", () => {
275
316
coolShadow: 0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14);
276
317
}
277
318
.foo { box-shadow: 0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14); }
278
- `
319
+ ` ,
320
+ messages : [
321
+ getMsg (
322
+ "coolShadow" ,
323
+ "0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14)"
324
+ )
325
+ ]
279
326
} ) ;
280
327
} ) ;
281
328
@@ -296,7 +343,8 @@ test("warn if value already declared and override result", () => {
296
343
}
297
344
.foo { color: __value__red__0 }
298
345
` ,
299
- warnings : [ `"red" value already declared` , `"red" value already declared` ]
346
+ warnings : [ `"red" value already declared` , `"red" value already declared` ] ,
347
+ messages : [ getMsg ( "red" , "__value__red__0" ) ]
300
348
} ) ;
301
349
} ) ;
302
350
@@ -320,7 +368,8 @@ test("reuse existing :import with same name and :export", () => {
320
368
b: i__c;
321
369
a: __value__a__0
322
370
}
323
- `
371
+ ` ,
372
+ messages : [ getMsg ( "a" , "__value__a__0" ) ]
324
373
} ) ;
325
374
} ) ;
326
375
@@ -370,6 +419,12 @@ test("warn on using dot or hash in value name", () => {
370
419
`Dot and hash symbols are not allowed in value "colors#blue"` ,
371
420
`Dot and hash symbols are not allowed in value ".red"` ,
372
421
`Dot and hash symbols are not allowed in value "#blue"`
422
+ ] ,
423
+ messages : [
424
+ getMsg ( "colors.red" , "#f00" ) ,
425
+ getMsg ( "colors#blue" , "#00f" ) ,
426
+ getMsg ( ".red" , "__value___red__0" ) ,
427
+ getMsg ( "#blue" , "__value___blue__1" )
373
428
]
374
429
} ) ;
375
430
} ) ;
0 commit comments