@@ -5,14 +5,20 @@ var test = require("tape")
5
5
var postcss = require ( "postcss" )
6
6
var plugin = require ( ".." )
7
7
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
+ }
10
15
11
16
function compareFixtures ( t , name , msg , opts , postcssOpts ) {
12
17
postcssOpts = postcssOpts || { }
13
18
postcssOpts . from = filename ( "fixtures/" + name )
14
19
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
16
22
var expected = read ( filename ( "fixtures/" + name + ".expected" ) )
17
23
fs . writeFile ( filename ( "fixtures/" + name + ".actual" ) , actual )
18
24
t . equal ( actual , expected , msg )
@@ -26,8 +32,8 @@ test("color()", function(t) {
26
32
test ( "logs warning when color() value cannot be parsed" , function ( t ) {
27
33
postcss ( plugin ( ) ) . process ( read ( filename ( "fixtures/error" ) ) )
28
34
. 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" )
31
37
32
38
var warning = warnings [ 0 ]
33
39
t . equals (
@@ -45,55 +51,58 @@ test("logs warning when color() value cannot be parsed", function(t) {
45
51
t . equals (
46
52
warning . text ,
47
53
"<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"
49
56
)
50
57
51
58
t . end ( )
52
59
} )
53
60
} )
54
61
55
62
test ( "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
+ )
64
85
65
86
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 "
69
90
)
70
91
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
+ )
96
97
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
+ )
98
104
} )
105
+
106
+ t . end ( )
107
+ } )
99
108
} )
0 commit comments