@@ -5,14 +5,20 @@ var test = require("tape")
55var postcss = require ( "postcss" )
66var plugin = require ( ".." )
77
8- function filename ( name ) { return "test/" + name + ".css" }
9- function read ( name ) { return fs . readFileSync ( name , "utf8" ) }
8+ function filename ( name ) {
9+ return "test/" + name + ".css"
10+ }
11+
12+ function read ( name ) {
13+ return fs . readFileSync ( name , "utf8" )
14+ }
1015
1116function compareFixtures ( t , name , msg , opts , postcssOpts ) {
1217 postcssOpts = postcssOpts || { }
1318 postcssOpts . from = filename ( "fixtures/" + name )
1419 opts = opts || { }
15- var actual = postcss ( ) . use ( plugin ( opts ) ) . process ( read ( postcssOpts . from ) , postcssOpts ) . css
20+ var actual = postcss ( ) . use ( plugin ( opts ) )
21+ . process ( read ( postcssOpts . from ) , postcssOpts ) . css
1622 var expected = read ( filename ( "fixtures/" + name + ".expected" ) )
1723 fs . writeFile ( filename ( "fixtures/" + name + ".actual" ) , actual )
1824 t . equal ( actual , expected , msg )
@@ -26,8 +32,8 @@ test("color()", function(t) {
2632test ( "logs warning when color() value cannot be parsed" , function ( t ) {
2733 postcss ( plugin ( ) ) . process ( read ( filename ( "fixtures/error" ) ) )
2834 . then ( function ( result ) {
29- var warnings = result . warnings ( ) ;
30- t . equals ( warnings . length , 1 , "expected only 1 warning" ) ;
35+ var warnings = result . warnings ( )
36+ t . equals ( warnings . length , 1 , "expected only 1 warning" )
3137
3238 var warning = warnings [ 0 ]
3339 t . equals (
@@ -45,55 +51,58 @@ test("logs warning when color() value cannot be parsed", function(t) {
4551 t . equals (
4652 warning . text ,
4753 "<css input>:2:3: Unable to parse color from string \"blurp\"" ,
48- "expected `warning.text` to contain a readable error when a color can't be parsed"
54+ "expected `warning.text` to contain a readable error " +
55+ "when a color can't be parsed"
4956 )
5057
5158 t . end ( )
5259 } )
5360} )
5461
5562test ( "logs message when color() contains var() custom property" , function ( t ) {
56- postcss ( plugin ( ) ) . process ( read ( filename ( "fixtures/color-with-custom-properties" ) ) )
57- . then ( function ( result ) {
58- const expectedWords = [
59- "color(var(--red))" ,
60- "color(var(--red) tint(50%))" ,
61- "color(var(--red) tint(var(--tintPercent)))" ,
62- "color(rgb(255, 0, 0) tint(var(--tintPercent)))"
63- ]
63+ postcss ( plugin ( ) ) . process (
64+ read ( filename ( "fixtures/color-with-custom-properties" ) )
65+ ) . then ( function ( result ) {
66+ var expectedWords = [
67+ "color(var(--red))" ,
68+ "color(var(--red) tint(50%))" ,
69+ "color(var(--red) tint(var(--tintPercent)))" ,
70+ "color(rgb(255, 0, 0) tint(var(--tintPercent)))" ,
71+ ]
72+
73+ t . equal (
74+ result . messages . length ,
75+ expectedWords . length ,
76+ "expected a message every time a color function is skipped"
77+ )
78+
79+ result . messages . forEach ( function ( message , i ) {
80+ t . equal (
81+ message . type ,
82+ "skipped-color-function-with-custom-property" ,
83+ "expected `message.type` to indicate reason for message"
84+ )
6485
6586 t . equal (
66- result . messages . length ,
67- expectedWords . length ,
68- "expected a message every time a color function is skipped "
87+ message . plugin ,
88+ "postcss-color-function" ,
89+ "expected ` message.plugin` to match this plugin's name "
6990 )
7091
71- result . messages . forEach ( function ( message , i ) {
72- t . equal (
73- message . type ,
74- "skipped-color-function-with-custom-property" ,
75- "expected `message.type` to indicate reason for message"
76- )
77-
78- t . equal (
79- message . plugin ,
80- "postcss-color-function" ,
81- "expected `message.plugin` to match this plugin's name"
82- )
83-
84- t . equal (
85- message . word ,
86- expectedWords [ i ] ,
87- "expected `message.word` to contain declaration value"
88- )
89-
90- t . equal (
91- message . message ,
92- "Skipped color function with custom property `" + expectedWords [ i ] + "`" ,
93- "expected `message.message` to contain reason for message"
94- )
95- } )
92+ t . equal (
93+ message . word ,
94+ expectedWords [ i ] ,
95+ "expected `message.word` to contain declaration value"
96+ )
9697
97- t . end ( )
98+ t . equal (
99+ message . message ,
100+ "Skipped color function with custom property " +
101+ "`" + expectedWords [ i ] + "`" ,
102+ "expected `message.message` to contain reason for message"
103+ )
98104 } )
105+
106+ t . end ( )
107+ } )
99108} )
0 commit comments