-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.test.js
121 lines (108 loc) · 3.11 KB
/
index.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
let postcss = require('postcss');
let plugin = require('./');
async function run (input, output, opts) {
let result = await postcss([plugin(opts)]).process(input, { from: undefined })
expect(result.css).toEqual(output);
expect(result.warnings()).toHaveLength(0)
}
it('changes vh', async () => {
await run(
'a{ height: 10vh; color: #FF10GG; }',
'a{ height: 10vh; height: calc(var(--vh, 1vh) * 10); color: #FF10GG; }',
{}
)
});
it('changes negative vh', async () => {
await run(
'a{ height: -10vh; color: #FF10GG; }',
'a{ height: -10vh; height: calc(var(--vh, 1vh) * -10); color: #FF10GG; }',
{}
)
});
it('does not have any change in priority', async () => {
await run(
'a{ height: 100px; height: 10vh; color: #FF10GG; }',
'a{ height: 100px; height: 10vh; height: calc(var(--vh, 1vh) * 10); ' +
'color: #FF10GG; }',
{}
)
});
it('does not override any following height declaration', async () => {
await run(
'a{ height: 10vh; height: 100px; }',
'a{ height: 10vh; height: calc(var(--vh, 1vh) * 10); height: 100px; }',
{}
)
});
it('works in another calc', async () => {
await run(
'a{ height: calc(10vh - 100px); }',
'a{ height: calc(10vh - 100px); ' +
'height: calc(calc(var(--vh, 1vh) * 10) - 100px); }',
{}
)
});
it('works in another calc with negative numbers', async () => {
await run(
'a{ height: calc(-10vh - 100px); }',
'a{ height: calc(-10vh - 100px); ' +
'height: calc(calc(var(--vh, 1vh) * -10) - 100px); }',
{}
)
});
it('multiple vh in one declaration', async () => {
await run(
'a{ height: calc(10vh * 3 + 20vh);}',
'a{ height: calc(10vh * 3 + 20vh); ' +
'height: calc(calc(var(--vh, 1vh) * 10) * 3 + calc(var(--vh, 1vh) * 20));}',
{}
)
});
it('does not have any effect on parsed', async () => {
await run(
'a{ height: calc(var(--vh, 1vh) * 10); color: #FF10GG; }',
'a{ height: calc(var(--vh, 1vh) * 10); color: #FF10GG; }',
{}
)
});
it('does not affect !important directive', async () => {
await run(
'a{ ' +
' height: 10vh !important; ' +
' max-height: 20vh ! important; ' +
' color: #FF10GG; ' +
'}',
'a{ ' +
' height: 10vh !important; ' +
' height: calc(var(--vh, 1vh) * 10) !important; ' +
' max-height: 20vh ! important; ' +
' max-height: calc(var(--vh, 1vh) * 20) ! important; ' +
' color: #FF10GG; ' +
'}',
{}
)
});
it('custom variable conf', async () => {
await run(
'a{ height: 10vh; color: #FF10GG; }',
'a{ height: 10vh; height: calc(var(--uu, 1vh) * 10); color: #FF10GG; }',
{ variable: 'uu' }
)
});
it('does not affect !important directive with custom variable', async () => {
await run(
'a{ ' +
' height: 10vh !important; ' +
' max-height: 20vh ! important; ' +
' color: #FF10GG; ' +
'}',
'a{ ' +
' height: 10vh !important; ' +
' height: calc(var(--someVariablePoints, 1vh) * 10) !important; ' +
' max-height: 20vh ! important; ' +
' max-height: calc(var(--someVariablePoints, 1vh) * 20) ! important; ' +
' color: #FF10GG; ' +
'}',
{ variable: 'someVariablePoints' }
)
});