-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
133 lines (125 loc) · 3.6 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
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
122
123
124
125
126
127
128
129
130
131
132
133
var test = require('tape');
var postcss = require('postcss');
var plugin = require('./');
var name = require('./package.json').name;
var tests = [
{
should: 'throw on invalid mode',
input: '',
options: { mode: "???" },
error: /'global', 'local' or 'pure'/
},
{
should: 'throw on inconsistent selector result',
input: ':global .foo, .bar {}',
error: /Inconsistent/
},
{
should: 'throw on nested :locals',
input: ':local(:local(.foo)) {}',
error: /is not allowed inside/
},
{
should: 'throw on nested :globals',
input: ':global(:global(.foo)) {}',
error: /is not allowed inside/
},
{
should: 'throw on nested mixed',
input: ':local(:global(.foo)) {}',
error: /is not allowed inside/
},
{
should: 'throw on nested broad :local',
input: ':global(:local .foo) {}',
error: /is not allowed inside/
},
{
should: 'throw on incorrect spacing with broad :global',
input: '.foo :global.bar {}',
error: /Missing whitespace after :global/
},
{
should: 'throw on incorrect spacing with broad :local',
input: '.foo:local .bar {}',
error: /Missing whitespace before :local/
},
{
should: 'throw on not pure selector (global class)',
input: ':global(.foo) {}',
options: { mode: "pure" },
error: /':global\(\.foo\)' is not pure/
},
{
should: 'throw on not pure selector (with multiple 1)',
input: '.foo, :global(.bar) {}',
options: { mode: "pure" },
error: /'.foo, :global\(\.bar\)' is not pure/
},
{
should: 'throw on not pure selector (with multiple 2)',
input: ':global(.bar), .foo {}',
options: { mode: "pure" },
error: /':global\(\.bar\), .foo' is not pure/
},
{
should: 'throw on not pure selector (element)',
input: 'input {}',
options: { mode: "pure" },
error: /'input' is not pure/
},
{
should: 'throw on not pure selector (attribute)',
input: '[type="radio"] {}',
options: { mode: "pure" },
error: /'\[type="radio"\]' is not pure/
},
{
should: 'throw on not pure keyframes',
input: '@keyframes :global(foo) {}',
options: { mode: "pure" },
error: /@keyframes :global\(\.\.\.\) is not allowed in pure mode/
},
{
should: 'throw on implicit global element',
input: 'input {}',
error: /'input' must be explicitly flagged with :global/
},
{
should: 'throw on implicit global element (with multiple 1)',
input: 'input, .foo {}',
error: /'input, \.foo' must be explicitly flagged with :global/
},
{
should: 'throw on implicit global element (with multiple 2)',
input: '.foo, input {}',
error: /'\.foo, input' must be explicitly flagged with :global/
},
{
should: 'throw on implicit global attribute',
input: '[type="radio"] {}',
error: /'\[type="radio"\]' must be explicitly flagged with :global/
},
{
should: 'throw on implicit global attribute in nested',
input: ':not([type="radio"]) {}',
error: /':not\(\[type="radio"\]\)' must be explicitly flagged with :global/
}
];
function process (css, options) {
return postcss(plugin(options)).process(css).css;
}
test(name, function (t) {
t.plan(tests.length);
tests.forEach(function (testCase) {
var options = testCase.options || {};
t.throws(function() {
process(testCase.input, options);
}, testCase.error, 'should ' + testCase.should);
});
});
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');
});