-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
93 lines (87 loc) · 2.87 KB
/
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
var test = require('tape');
var postcss = require('postcss');
var plugin = require('./');
var name = require('./package.json').name;
var tests = [
{
message: 'when use any selector and subtract signal',
fixture: '#a-abc{ } .abc-def{ }',
expected: '#myPrefix_a-abc{ } .myPrefix_abc-def{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use class selector with space',
fixture: '.a{ } .abc{ }',
expected: '.myPrefix_a{ } .myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use class selector without space',
fixture: '.a{ }.abc{ }',
expected: '.myPrefix_a{ }.myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id selector with space',
fixture: '#a{ } #abc{ }',
expected: '#myPrefix_a{ } #myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id selector without space',
fixture: '#a{ }#abc{ }',
expected: '#myPrefix_a{ }#myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id and class selector with space',
fixture: '#a{ } .abc{ }',
expected: '#myPrefix_a{ } .myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id and class selector without space',
fixture: '#a{ }.abc{ }',
expected: '#myPrefix_a{ }.myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id and class selector with child combinator',
fixture: '#a > .abc{ }',
expected: '#myPrefix_a > .myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id and class selector with adjacent sibling combinator',
fixture: '#a + .abc{ }',
expected: '#myPrefix_a + .myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id and class selector with general sibling combinator',
fixture: '#a ~ .abc{ }',
expected: '#myPrefix_a ~ .myPrefix_abc{ }',
options: {prefix: 'myPrefix_'}
},
{
message: 'when use id and class selector with :hover selector',
fixture: '#a:hover { }',
expected: '#myPrefix_a:hover { }',
options: {prefix: 'myPrefix_'}
}
];
function process (css, options) {
return postcss(plugin(options)).process(css).css;
}
test(name, function (t) {
t.plan(tests.length);
tests.forEach(function (test) {
var options = test.options || {};
t.equal(process(test.fixture, options), test.expected, test.message);
});
});
test('should use the postcss plugin api', function (t) {
t.plan(2);
t.ok(plugin().postcssVersion, 'should be able to access version');
t.equal(plugin().postcssPlugin, name, 'should be able to access name');
});