/
optimize-test.js
117 lines (116 loc) · 3.5 KB
/
optimize-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
var vows = require('vows');
var optimizerContext = require('../../test-helper').optimizerContext;
vows.describe('level 2 optimizer')
.addBatch(
optimizerContext('all optimizations', {
'adjacent': [
'a{display:none}a{display:none;visibility:hidden}',
'a{display:none;visibility:hidden}'
],
'overriding by !important': [
'a{margin:0}a{margin:0!important}',
'a{margin:0!important}'
],
'shorthands and no space after closing brace': [
'.a{background:rgba(0,0,0,0)url(//example.com/a.jpg)}',
'.a{background:url(//example.com/a.jpg) rgba(0,0,0,0)}'
],
'repeated': [
'a{color:red;color:red}',
'a{color:red}'
],
'units': [
'.one{width:1px;width:1rem;display:block}.two{color:red}.one{width:2px;width:1.1rem}',
'.one{display:block;width:1.1rem}.two{color:red}'
],
'backslash hacks': [
'.block{color:red\\9;color:#0f0\\0}',
''
]
}, { level: 2 })
)
.addBatch(
optimizerContext('in ie8 compatibility mode', {
'backslash hacks': [
'.block{color:red\\9;color:#0f0\\0}',
'.block{color:red\\9;color:#0f0\\0}'
]
}, { compatibility: 'ie8', level: 2 })
)
.addBatch(
optimizerContext('level 2 off', {
'repeated' : [
'a{color:red;color:red}',
'a{color:red;color:red}'
]
}, { level: 1 })
)
.addBatch(
optimizerContext('@media', {
'empty': [
'@media (min-width:980px){}',
''
],
'whitespace': [
' @media ( min-width: 980px ){}',
''
],
'body': [
'@media (min-width:980px){\na\n{color:red}}',
'@media (min-width:980px){a{color:red}}'
],
'multiple': [
'@media screen, print, (min-width:980px){a{color:red}}',
'@media screen,print,(min-width:980px){a{color:red}}'
],
'nested once': [
'@media screen { @media print { a{color:red} } }',
'@media screen{@media print{a{color:red}}}'
],
'nested twice': [
'@media screen { @media print { @media (min-width:980px) { a{color:red} } } }',
'@media screen{@media print{@media (min-width:980px){a{color:red}}}}'
]
}, { level: 2 })
)
.addBatch(
optimizerContext('@font-face', {
'rebuilding': [
'@font-face{font-family:PublicVintage;src:url(/PublicVintage.otf) format(\'opentype\')}',
'@font-face{font-family:PublicVintage;src:url(/PublicVintage.otf) format(\'opentype\')}'
]
}, { level: 2 })
)
.addBatch(
optimizerContext('unit merging', {
'font-size': [
'div{font-size:1rem;font-size:16px}',
'div{font-size:16px}'
],
'height': [
'div{height:1rem;height:16px}',
'div{height:16px}'
],
'width': [
'div{width:1rem;width:16px}',
'div{width:16px}'
]
}, { level: 2 })
)
.addBatch(
optimizerContext('variables', {
'skip processing properties with variable values - border - 1st value': [
'.one{border:var(--color) solid 1px}',
'.one{border:var(--color) solid 1px}'
],
'skip processing properties with variable values - border - 2nd value': [
'.one{border:red var(--style) 1px}',
'.one{border:red var(--style) 1px}'
],
'skip processing properties with variable values - border - 3rd value': [
'.one{border:red solid var(--width)}',
'.one{border:red solid var(--width)}'
]
}, { level: 2 })
)
.export(module);