@@ -9,12 +9,23 @@ const compile = input => postcss([plugin]).process(strip(input));
99
1010const getWarnings = result => result . warnings ( ) . map ( warning => warning . text ) ;
1111
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 = [ ] } ) =>
1316 compile ( fixture ) . then ( result => {
14- expect ( getWarnings ( result ) ) . toEqual ( warnings ) ;
1517 expect ( result . css . trim ( ) ) . toEqual ( strip ( expected ) ) ;
18+ expect ( getWarnings ( result ) ) . toEqual ( warnings ) ;
19+ expect ( getMessages ( result ) ) . toEqual ( messages ) ;
1620 } ) ;
1721
22+ const getMsg = ( name , value ) => ( {
23+ plugin : "postcss-icss-values" ,
24+ type : "icss-value" ,
25+ name,
26+ value
27+ } ) ;
28+
1829test ( "export value" , ( ) => {
1930 return run ( {
2031 fixture : `
@@ -26,7 +37,11 @@ test("export value", () => {
2637 red: 1px solid #f00;
2738 blue: 1px solid #00f
2839 }
29- `
40+ ` ,
41+ messages : [
42+ getMsg ( "red" , "1px solid #f00" ) ,
43+ getMsg ( "blue" , "1px solid #00f" )
44+ ]
3045 } ) ;
3146} ) ;
3247
@@ -56,7 +71,8 @@ test("replace values within the file", () => {
5671 @media red {
5772 .red { color: red }
5873 }
59- `
74+ ` ,
75+ messages : [ getMsg ( "blue" , "red" ) ]
6076 } ) ;
6177} ) ;
6278
@@ -74,7 +90,8 @@ test("import external values", () => {
7490 red: __value__red__0
7591 }
7692 .foo { color: __value__red__0 }
77- `
93+ ` ,
94+ messages : [ getMsg ( "red" , "__value__red__0" ) ]
7895 } ) ;
7996} ) ;
8097
@@ -99,7 +116,13 @@ test("import multiple external values", () => {
99116 green: __value__green__2;
100117 yellow: __value__yellow__3
101118 }
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+ ]
103126 } ) ;
104127} ) ;
105128
@@ -119,7 +142,11 @@ test("import external values with aliases", () => {
119142 blue1: __value__blue1__1
120143 }
121144 .foo { color: __value__red1__0; background: blue }
122- `
145+ ` ,
146+ messages : [
147+ getMsg ( "red1" , "__value__red1__0" ) ,
148+ getMsg ( "blue1" , "__value__blue1__1" )
149+ ]
123150 } ) ;
124151} ) ;
125152
@@ -144,7 +171,11 @@ test("import multiple values grouped with parentheses on multiple lines", () =>
144171 }
145172 .foo { color: __value__red__1; }
146173 .bar { color: __value__blue__0 }
147- `
174+ ` ,
175+ messages : [
176+ getMsg ( "blue" , "__value__blue__0" ) ,
177+ getMsg ( "red" , "__value__red__1" )
178+ ]
148179 } ) ;
149180} ) ;
150181
@@ -191,7 +222,8 @@ test("allow transitive values", () => {
191222 bbb: red;
192223 }
193224 .a { color: red; }
194- `
225+ ` ,
226+ messages : [ getMsg ( "aaa" , "red" ) , getMsg ( "bbb" , "red" ) ]
195227 } ) ;
196228} ) ;
197229
@@ -208,7 +240,8 @@ test("allow transitive values within calc", () => {
208240 large: calc(10px * 2);
209241 }
210242 .a { margin: calc(10px * 2); }
211- `
243+ ` ,
244+ messages : [ getMsg ( "base" , "10px" ) , getMsg ( "large" , "calc(10px * 2)" ) ]
212245 } ) ;
213246} ) ;
214247
@@ -225,7 +258,8 @@ test("allow custom-property-style names", () => {
225258 --red: __value____red__0;
226259 }
227260 .foo { color: __value____red__0; }
228- `
261+ ` ,
262+ messages : [ getMsg ( "--red" , "__value____red__0" ) ]
229263 } ) ;
230264} ) ;
231265
@@ -260,7 +294,14 @@ test("allow all colour types", () => {
260294 border-bottom-color: rgba(34, 12, 64, 0.3);
261295 outline-color: hsla(220, 13.0%, 18.0%, 1);
262296 }
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+ ]
264305 } ) ;
265306} ) ;
266307
@@ -275,7 +316,13 @@ test("allow definitions with commas in them", () => {
275316 coolShadow: 0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14);
276317 }
277318 .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+ ]
279326 } ) ;
280327} ) ;
281328
@@ -296,7 +343,8 @@ test("warn if value already declared and override result", () => {
296343 }
297344 .foo { color: __value__red__0 }
298345 ` ,
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" ) ]
300348 } ) ;
301349} ) ;
302350
@@ -320,7 +368,8 @@ test("reuse existing :import with same name and :export", () => {
320368 b: i__c;
321369 a: __value__a__0
322370 }
323- `
371+ ` ,
372+ messages : [ getMsg ( "a" , "__value__a__0" ) ]
324373 } ) ;
325374} ) ;
326375
@@ -370,6 +419,12 @@ test("warn on using dot or hash in value name", () => {
370419 `Dot and hash symbols are not allowed in value "colors#blue"` ,
371420 `Dot and hash symbols are not allowed in value ".red"` ,
372421 `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" )
373428 ]
374429 } ) ;
375430} ) ;
0 commit comments