-
-
Notifications
You must be signed in to change notification settings - Fork 319
/
index.js
172 lines (148 loc) · 5.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import test from 'ava';
import plugin from '..';
import {usePostCSSPlugin, processCSSFactory} from '../../../../util/testHelpers';
const {passthroughCSS, processCSS} = processCSSFactory(plugin);
test(
'should remove unused counter styles',
processCSS,
'@counter-style custom{system:extends decimal;suffix:"> "}',
''
);
test(
'should be aware of extensions',
passthroughCSS,
'@counter-style custom{system:extends decimal;suffix:"> "}@counter-style custom2{system:extends custom;suffix:"| "}a{list-style: custom2}'
);
test(
'should remove unused counters & keep used counters',
processCSS,
'@counter-style custom{system:extends decimal;suffix:"> "}@counter-style custom2{system:extends decimal;suffix:"| "}a{list-style: custom2}',
'@counter-style custom2{system:extends decimal;suffix:"| "}a{list-style: custom2}'
);
test(
'should remove counter styles if they have no identifier',
processCSS,
'@counter-style {system:extends decimal;suffix:"> "}',
''
);
test(
'should remove unused keyframes',
processCSS,
'@keyframes fadeOut{0%{opacity:1}to{opacity:0}}',
''
);
test(
'should remove unused keyframes & keep used keyframes',
processCSS,
'@keyframes fadeOut{0%{opacity:1}to{opacity:0}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}a{animation-name:fadeIn}',
'@keyframes fadeIn{0%{opacity:0}to{opacity:1}}a{animation-name:fadeIn}'
);
test(
'should remove keyframes if they have no identifier',
processCSS,
'@keyframes {0%{opacity:0}to{opacity:1}}',
''
);
test(
'should support multiple animations',
passthroughCSS,
'@keyframes one{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}@keyframes two{0%{border-width:0;opacity:0}}.loader{animation:one 1250ms infinite linear,two .3s ease-out both}'
);
test(
'should remove unused fonts',
processCSS,
'@font-face {font-family:"Does Not Exist";src:url("fonts/does-not-exist.ttf") format("truetype")}',
''
);
test(
'should remove unused fonts (2)',
processCSS,
'@font-face {font-family:"Does Not Exist";src:url("fonts/does-not-exist.ttf") format("truetype")}@font-face {font-family:"Does Exist";src: url("fonts/does-exist.ttf") format("truetype")}',
''
);
test(
'should remove unused fonts & keep used fonts',
processCSS,
'@font-face {font-family:"Does Not Exist";src:url("fonts/does-not-exist.ttf") format("truetype")}@font-face {font-family:"Does Exist";src: url("fonts/does-exist.ttf") format("truetype")}body{font-family:"Does Exist",Helvetica,Arial,sans-serif}',
'@font-face {font-family:"Does Exist";src: url("fonts/does-exist.ttf") format("truetype")}body{font-family:"Does Exist",Helvetica,Arial,sans-serif}'
);
test(
'should work with the font shorthand',
passthroughCSS,
'@font-face {font-family:"Does Exist";src: url("fonts/does-exist.ttf") format("truetype")}body{font: 10px/1.5 "Does Exist",Helvetica,Arial,sans-serif}'
);
test(
'should normalize fonts',
passthroughCSS,
'@font-face {font-family:"Does Exist";src:url("fonts/does-exist.ttf") format("truetype")}body{font-family:Does Exist}',
);
test(
'should work with mixed quote styles',
passthroughCSS,
'@font-face {font-family:"Does Exist";src:url("fonts/does-exist.ttf") format("truetype")}@font-face {font-family:\'DoesExist\';src:url("fonts/does-exist.ttf") format("truetype")}body{font-family: \'Does Exist\'; font: 10px DoesExist}'
);
test(
'should work spaces in font lists',
passthroughCSS,
'@font-face {font-family:"Does Exist";src: url("fonts/does-exist.ttf") format("truetype")} @font-face {font-family:\'DoesExist\';src:url("fonts/does-exist.ttf") format("truetype")} body { font-family: "Does Exist", Helvetica, Arial, sans-serif; font: 10px/1.5 DoesExist, Helvetica, Arial, sans-serif }'
);
test(
'should work with weird font names',
passthroughCSS,
'@font-face {font-family:"ൠ😳ฬ𝔢IяĎ 🐉💩👍Iñtërnâtiônàlizætiøn☃💩";src: url("fonts/weird.woff") format("truetype")}body {font-family: "ൠ😳ฬ𝔢IяĎ 🐉💩👍Iñtërnâtiônàlizætiøn☃💩"}'
);
test(
"should handle font shorthands that don't include a font-family",
processCSS,
'@font-face {font-family:"Does Exist";src: url("fonts/does-exist.ttf") format("truetype")}body{font: italic bold 10px/1.5}',
'body{font: italic bold 10px/1.5}'
);
test(
'should remove font faces if they have no font-family property',
processCSS,
'@font-face {src:url("fonts/does-not-exist.ttf") format("truetype")}',
''
);
test(
'should not remove fonts used with a different casing',
passthroughCSS,
'@font-face {font-family:"DoEs ExIst";src: url("fonts/does-exist.ttf") format("truetype")}body{font: 10px/1.5 "does exisT",Helvetica,Arial,sans-serif}'
);
test(
'shouldn\'t remove font fames',
processCSS,
[
'@font-face {src:url("fonts/does-not-exist.ttf") format("truetype")}',
'@keyframes {0%{opacity:0}to{opacity:1}}',
'@counter-style custom{system:extends decimal;suffix:"> "}',
].join(''),
'@font-face {src:url("fonts/does-not-exist.ttf") format("truetype")}',
{fontFace: false}
);
test(
'shouldn\'t remove keyframes if they have no identifier',
processCSS,
[
'@keyframes {0%{opacity:0}to{opacity:1}}',
'@font-face {src:url("fonts/does-not-exist.ttf") format("truetype")}',
'@counter-style custom{system:extends decimal;suffix:"> "}',
].join(''),
'@keyframes {0%{opacity:0}to{opacity:1}}',
{keyframes: false}
);
test(
'shouldn\'t remove unused counter styles',
processCSS,
[
'@counter-style custom{system:extends decimal;suffix:"> "}',
'@font-face {src:url("fonts/does-not-exist.ttf") format("truetype")}',
'@keyframes {0%{opacity:0}to{opacity:1}}',
].join(''),
'@counter-style custom{system:extends decimal;suffix:"> "}',
{counterStyle: false}
);
test(
'should use the postcss plugin api',
usePostCSSPlugin,
plugin()
);