Debian Codegraph @

autoprefixer/test/supports.test.js

raw symbols SCIP
1 let { test } = require('uvu')
2 let { equal } = require('uvu/assert')
3
4 let brackets = require('../lib/brackets')
5 let Browsers = require('../lib/browsers')
6 let Prefixes = require('../lib/prefixes')
7 let Supports = require('../lib/supports')
8
9 let browsers = new Browsers(
10 {
11 firefox: {
12 prefix: 'moz',
13 versions: ['firefox 22']
14 }
15 },
16 ['firefox 22', 'firefox 21']
17 )
18 let prefixes = new Prefixes(
19 {
20 a: {
21 browsers: ['firefox 22']
22 },
23 b: {
24 browsers: ['firefox 22'],
25 props: 'c'
26 }
27 },
28 browsers
29 )
30 let supports = new Supports(Prefixes, prefixes)
31
32 function rm(str) {
33 let ast = supports.normalize(brackets.parse(str))
34 return brackets.stringify(supports.remove(ast, str))
35 }
36
37 function clean(str) {
38 let ast = supports.normalize(brackets.parse(str))
39 return brackets.stringify(supports.cleanBrackets(ast))
40 }
41
42 test('splits property name and value', () => {
43 equal(supports.parse('color:black'), ['color', 'black'])
44 })
45
46 test('cleans spaces', () => {
47 equal(supports.parse(' color : black '), ['color', 'black'])
48 })
49
50 test('parses everything', () => {
51 equal(supports.parse('color'), ['color', ''])
52 })
53
54 test('returns virtual rule', () => {
55 let decl = supports.virtual('color: black')
56 equal(decl.type, 'rule')
57 equal(decl.toString(), 'a{color: black}')
58 })
59
60 test('works with broken CSS', () => {
61 let decl = supports.virtual('color black')
62 equal(decl.type, 'rule')
63 })
64
65 test('returns decls with prefixed property', () => {
66 let decls = supports.prefixed('a: one')
67
68 equal(decls.length, 2)
69 equal(decls[0].toString(), '-moz-a: one')
70 equal(decls[1].toString(), 'a: one')
71 })
72
73 test('returns decls with prefixed value', () => {
74 let decls = supports.prefixed('c: b')
75
76 equal(decls.length, 2)
77 equal(decls[0].toString(), 'c: -moz-b')
78 equal(decls[1].toString(), 'c: b')
79 })
80
81 test('reduces empty string', () => {
82 equal(supports.normalize([['', ['a'], '']]), [[['a']]])
83 })
84
85 test('reduces declaration to string', () => {
86 equal(supports.normalize(['a: b', ['1']]), ['a: b(1)'])
87 })
88
89 test('reduces wrapped declaration to string', () => {
90 equal(supports.normalize(['', ['a: b', ['1']], '']), [['a: b(1)']])
91 })
92
93 test('remove prefixed properties', () => {
94 equal(rm('(-moz-a: 1) or (a: 1)'), '(a: 1)')
95 })
96
97 test('remove prefixed properties inside', () => {
98 equal(rm('(((-moz-a: 1) or (a: 1)))'), '(((a: 1)))')
99 })
100
101 test('remove prefixed values', () => {
102 equal(rm('(c: -moz-b) or (c: -b-)'), '(c: -b-)')
103 })
104
105 test('keeps and-conditions', () => {
106 equal(rm('(-moz-a: 1) and (a: 1)'), '(-moz-a: 1) and (a: 1)')
107 })
108
109 test('keeps not-conditions', () => {
110 equal(rm('not (-moz-a: 1) or (a: 1)'), 'not (-moz-a: 1) or (a: 1)')
111 })
112
113 test('keeps hacks', () => {
114 equal(rm('(-moz-a: 1) or (b: 2)'), '(-moz-a: 1) or (b: 2)')
115 })
116
117 test('uses only browsers with @supports support', () => {
118 equal(supports.prefixer().browsers.selected, ['firefox 22'])
119 })
120
121 test('normalize brackets', () => {
122 equal(clean('((a: 1))'), '(a: 1)')
123 })
124
125 test('normalize brackets recursively', () => {
126 equal(clean('(((a: 1) or ((b: 2))))'), '((a: 1) or (b: 2))')
127 })
128
129 test('adds params with prefixed value', () => {
130 let rule = { params: '(c: b)' }
131 supports.process(rule)
132 equal(rule.params, '((c: -moz-b) or (c: b))')
133 })
134
135 test('adds params with prefixed function', () => {
136 let rule = { params: '(c: b(1))' }
137 supports.process(rule)
138 equal(rule.params, '((c: -moz-b(1)) or (c: b(1)))')
139 })
140
141 test('replaces params with prefixed property', () => {
142 let rule = { params: '(color black) and not (a: 1)' }
143 supports.process(rule)
144 equal(rule.params, '(color black) and not ((-moz-a: 1) or (a: 1))')
145 })
146
147 test("shouldn't throw errors", () => {
148 let rule = { params: 'not selector(:is(a, b))' }
149 supports.process(rule)
150 equal(rule.params, 'not selector(:is(a, b))')
151 })
152
153 test("shouldn't throw errors (2)", () => {
154 let rule = { params: ' (selector( :nth-child(1n of a, b) )) or (c: b(1)) ' }
155 supports.process(rule)
156 equal(
157 rule.params,
158 ' (selector( :nth-child(1n of a, b) )) or ((c: -moz-b(1)) or (c: b(1))) '
159 )
160 })
161
162 test.run()