forked from honboubao/postcss-var-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
89 lines (80 loc) · 2.21 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
var postcss = require('postcss');
var plugin = require('./');
it('produces a correct CSS var map', () => {
const opts = {
mapFile: 'test/css-var-map.js',
mapPrefix: 'module.exports = ',
mapSuffix: '',
shimFile: 'test/css-var-shim.js'
};
const input = `
:root {
--tint: springgreen !important;
--hint: lemonchiffon;
}
body {
color: blueviolet;
background-color: var(--tint);
}
.button {
color: gray;
}
input[type='submit'],
input[type='submit'] {
color: var(--hint);
}
@media (min-width: 415px) {
.button {
--tint: rebeccapurple;
padding: 5px;
color: var(--tint, var(--hint, pink));
border-color: var(--hint);
}
}
`;
const output = {
getVars: {
'--tint': {
'body': {
0: [['background-color', 'var(--tint)']]
},
'.button': {
1: [
['color', 'var(--tint, var(--hint, pink))']
]
}
},
'--hint': {
'.button': {
1: [
['color', 'var(--tint, var(--hint, pink))'],
['border-color', 'var(--hint)']
]
},
'input[type=\'submit\'], input[type=\'submit\']': {
0: [
['color', 'var(--hint)']
]
}
}
},
setVars: [
[
'--tint', 'springgreen', 'important',
':root', 0
], [
'--hint', 'lemonchiffon', 0,
':root', 0
], [
'--tint', 'rebeccapurple', 0,
'.button', 1
]
]
};
return postcss([ plugin(opts) ]).process(input)
.then(result => {
const file = require('./test/css-var-map.js');
expect(file).toEqual(output);
expect(result.warnings().length).toBe(0);
});
});