/
remove-unused-at-rules-test.js
153 lines (152 loc) · 8.11 KB
/
remove-unused-at-rules-test.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
var vows = require('vows');
var optimizerContext = require('../../test-helper').optimizerContext;
vows.describe('remove unused at rules')
.addBatch(
optimizerContext('@counter-style', {
'one unused declaration': [
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}',
''
],
'one used declaration in list-style': [
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style:test}',
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style:test}'
],
'one used declaration in list-style-type': [
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style-type:test}',
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style-type:test}'
],
'one used declaration in nested list-style-type': [
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}@media screen{.block{list-style-type:test}}',
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}@media screen{.block{list-style-type:test}}'
],
'one used declaration and one unused': [
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}@counter-style test2{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style-type:test}',
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style-type:test}'
],
'one used declaration with !important': [
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style:test!important}',
'@counter-style test{system:fixed;symbols:url(one.png) url(two.png);suffix:" "}.block{list-style:test!important}'
]
}, { level: { 2: { removeUnusedAtRules: true } } })
)
.addBatch(
optimizerContext('@font-face', {
'one unused declaration': [
'@font-face{font-family:test}',
''
],
'one used declaration in font-family': [
'@font-face{font-family:test}.block{font-family:test}',
'@font-face{font-family:test}.block{font-family:test}'
],
'one used declaration in font-family with different case': [
'@font-face{font-family:test}.block{font-family:Test}',
'@font-face{font-family:test}.block{font-family:Test}'
],
'one used declaration in multi-valued font-family': [
'@font-face{font-family:test}.block{font-family:Arial,test,sans-serif}',
'@font-face{font-family:test}.block{font-family:Arial,test,sans-serif}'
],
'one used declaration in font': [
'@font-face{font-family:test}.block{font:16px test}',
'@font-face{font-family:test}.block{font:16px test}'
],
'one used declaration in multi-valued font': [
'@font-face{font-family:test}.block{font:16px Arial,test,sans-serif}',
'@font-face{font-family:test}.block{font:16px Arial,test,sans-serif}'
],
'one used declaration in nested font': [
'@font-face{font-family:test}@media screen{.block{font:16px test}}',
'@font-face{font-family:test}@media screen{.block{font:16px test}}'
],
'one used declaration in multi-valued font with different case': [
'@font-face{font-family:test}.block{font:16px Arial,Test,sans-serif}',
'@font-face{font-family:test}.block{font:16px Arial,Test,sans-serif}'
],
'one used declaration and one unused': [
'@font-face{font-family:test}@font-face{font-family:test2}.block{font:16px test}',
'@font-face{font-family:test}.block{font:16px test}'
],
'one used with !important': [
'@font-face{font-family:test}.block{font:16px test!important}',
'@font-face{font-family:test}.block{font:16px test!important}'
],
'one used declaration in another @font-face': [
'@font-face{font-family:test;font-weight:normal}@font-face{font-family:test;font-weight:bold}',
''
]
}, { level: { 2: { removeUnusedAtRules: true } } })
)
.addBatch(
optimizerContext('@keyframes', {
'one unused declaration': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}',
''
],
'one used declaration in animation-name': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation-name:test}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation-name:test}'
],
'one used declaration in multi-value animation-name': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation-name:custom,test}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation-name:custom,test}'
],
'one used declaration in animation': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in test}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in test}'
],
'one used declaration in multi-value animation': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in custom,2s ease-out test}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in custom,2s ease-out test}'
],
'one used declaration in vendor prefixed animation': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{-moz-animation:1s ease-in test}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{-moz-animation:1s ease-in test}'
],
'one used vendor prefixed declaration in animation': [
'@-webkit-keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in test}',
'@-webkit-keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in test}'
],
'one used in nested animation': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}@media screen{.block{animation:1s ease-in test}}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}@media screen{.block{animation:1s ease-in test}}'
],
'one used declaration and one unused': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}@keyframes test2{0%{opacity:0}100%{opacity:1}}.block{animation-name:test}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation-name:test}'
],
'one used with !important': [
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in test!important}',
'@keyframes test{0%{opacity:0}100%{opacity:1}}.block{animation:1s ease-in test!important}'
]
}, { level: { 2: { removeUnusedAtRules: true } } })
)
.addBatch(
optimizerContext('@namespace', {
'one unused declaration': [
'@namespace svg url(http://www.w3.org/2000/svg);',
''
],
'one used declaration in scope': [
'@namespace svg url(http://www.w3.org/2000/svg);svg|.block{color:red}',
'@namespace svg url(http://www.w3.org/2000/svg);svg|.block{color:red}'
],
'one used declaration in attribute': [
'@namespace svg url(http://www.w3.org/2000/svg);.block[svg|title=test]{color:red}',
'@namespace svg url(http://www.w3.org/2000/svg);.block[svg|title=test]{color:red}'
],
'one used declaration in nested attribute': [
'@namespace svg url(http://www.w3.org/2000/svg);@media screen{.block[svg|title=test]{color:red}}',
'@namespace svg url(http://www.w3.org/2000/svg);@media screen{.block[svg|title=test]{color:red}}'
],
'many declaration in one rule': [
'@namespace svg url(http://www.w3.org/2000/svg);@namespace xlink url(http://www.w3.org/2000/xlink);.block[svg|title=test],xlink|.block{color:red}',
'@namespace svg url(http://www.w3.org/2000/svg);@namespace xlink url(http://www.w3.org/2000/xlink);.block[svg|title=test],xlink|.block{color:red}'
],
'one used declaration and one unused': [
'@namespace svg url(http://www.w3.org/2000/svg);@namespace xlink url(http://www.w3.org/2000/xlink);svg|.block{color:red}',
'@namespace svg url(http://www.w3.org/2000/svg);svg|.block{color:red}'
]
}, { level: { 2: { removeUnusedAtRules: true } } })
)
.export(module);