-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.test.js
79 lines (67 loc) · 2.16 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
const postcss = require('postcss');
const plugin = require('./');
async function run(input, output, options = {}) {
const result = await postcss([plugin(options)]).process(input, { from: undefined })
expect(result.css).toEqual(output);
expect(result.warnings()).toHaveLength(0);
}
it('Simple', () => run(
'.simple { font-size: rem-convert(24px); }',
'.simple { font-size: 1.5rem; }'
));
it('Multiple values', () => run(
'.multiple { padding: rem-convert(5px 10px); }',
'.multiple { padding: 0.3125rem 0.625rem; }'
));
it('Multiple mixed values', () => run(
'.mixed { border-bottom: rem-convert(1px solid black); }',
'.mixed { border-bottom: 0.0625rem solid black; }'
));
it('Comma-separated values', () => run(
'.comma { box-shadow: rem-convert(0 0 2px #ccc, inset 0 0 5px #eee); }',
'.comma { box-shadow: 0 0 0.125rem #ccc, inset 0 0 0.3125rem #eee; }'
));
it('Alternate use', () => run(
'.alternate { text-shadow: rem-convert(1px 1px) #eee, rem-convert(-1px) 0 #eee; }',
'.alternate { text-shadow: 0.0625rem 0.0625rem #eee, -0.0625rem 0 #eee; }'
));
it('In function', () => run(
'.function { font-size: calc(rem-convert(16px) + 3vw); }',
'.function { font-size: calc(1rem + 3vw); }'
));
it('Pixel fallback', () => run(
'.fallback { font-size: rem-convert(24px); margin: rem-convert(10px 1.5rem); }',
'.fallback { font-size: 24px; font-size: 1.5rem; margin: 10px 24px; margin: 0.625rem 1.5rem; }',
{
fallback: true
}
));
it('Convert to pixel', () => run(
'.convert { font-size: rem-convert(24px); margin: rem-convert(10px 1.5rem); }',
'.convert { font-size: 24px; margin: 10px 24px; }',
{
convert: 'px'
}
));
it('Changing baseline', () => run(
'html { font-size: 62.5%; } .baseline { font-size: rem-convert(24px); }',
'html { font-size: 62.5%; } .baseline { font-size: 2.4rem; }',
{
baseline: 10
}
));
it('Changing precision', () => run(
'.precision { font-size: rem-convert(16px); }',
'.precision { font-size: 1.333rem; }',
{
baseline: 12,
precision: 3
}
));
it('Changing function name', () => run(
'.name { font-size: convert-rem(24px); }',
'.name { font-size: 1.5rem; }',
{
name: 'convert-rem',
}
));