|
| 1 | +var Promise = require('bluebird'); |
| 2 | +var fs = Promise.promisifyAll(require('fs')); |
| 3 | +var path = require('path'); |
| 4 | + |
1 | 5 | var chai = require('chai');
|
2 | 6 | var expect = chai.expect;
|
3 | 7 | var chaiAsPromised = require('chai-as-promised');
|
4 | 8 | chai.use(chaiAsPromised);
|
5 | 9 |
|
6 | 10 | var postcss = require('postcss');
|
| 11 | +var cssvariables = require('../'); |
7 | 12 |
|
8 |
| -var Promise = require('bluebird'); |
9 |
| -var fs = Promise.promisifyAll(require('fs')); |
10 | 13 | var CleanCSS = require('clean-css');
|
11 | 14 |
|
12 |
| -var cssvariables = require('../'); |
13 | 15 |
|
14 |
| -function testPlugin(filePath, expectedFilePath, options) { |
| 16 | +var testPlugin = function(filePath, expectedFilePath, options) { |
15 | 17 | options = options || {};
|
16 | 18 | return fs.readFileAsync(filePath)
|
17 | 19 | .then(function(buffer) {
|
@@ -39,204 +41,163 @@ function testPlugin(filePath, expectedFilePath, options) {
|
39 | 41 | //expect(actual).to.equal(contents);
|
40 | 42 | });
|
41 | 43 | });
|
42 |
| -} |
| 44 | +}; |
43 | 45 |
|
44 |
| -describe('postcss-css-variables', function() { |
45 |
| - |
46 |
| - |
47 |
| - // Just make sure it doesn't mangle anything |
48 |
| - it('should work when there are no var() functions to consume declarations', function() { |
49 |
| - return testPlugin('./test/fixtures/no-var-func.css', './test/fixtures/no-var-func.expected.css'); |
| 46 | +var fixtureBasePath = './test/fixtures/'; |
| 47 | +var test = function(message, fixtureName, options) { |
| 48 | + it(message, function() { |
| 49 | + return testPlugin( |
| 50 | + path.join(fixtureBasePath, fixtureName + '.css'), |
| 51 | + path.join(fixtureBasePath, fixtureName + '.expected.css'), |
| 52 | + options |
| 53 | + ); |
50 | 54 | });
|
| 55 | +}; |
51 | 56 |
|
52 |
| - it('should work when no variable name passed to `var()`', function() { |
53 |
| - return testPlugin('./test/fixtures/empty-var-func.css', './test/fixtures/empty-var-func.expected.css'); |
54 |
| - }); |
55 | 57 |
|
56 | 58 |
|
| 59 | +describe('postcss-css-variables', function() { |
57 | 60 |
|
58 |
| - it('should work with variables declared in root', function() { |
59 |
| - return testPlugin('./test/fixtures/root-variable.css', './test/fixtures/root-variable.expected.css'); |
60 |
| - }); |
61 |
| - |
62 |
| - it('should work with locally scoped variable in a non-root rule', function() { |
63 |
| - return testPlugin('./test/fixtures/local-variable-non-root.css', './test/fixtures/local-variable-non-root.expected.css'); |
64 |
| - }); |
65 | 61 |
|
66 |
| - it('should work with any combinator selector if the last piece is the variable we have in the map', function() { |
67 |
| - return testPlugin('./test/fixtures/scope-last-piece-of-combinator-sequence.css', './test/fixtures/scope-last-piece-of-combinator-sequence.expected.css'); |
68 |
| - }); |
| 62 | + // Just make sure it doesn't mangle anything |
| 63 | + test('should work when there are no var() functions to consume declarations', 'no-var-func'); |
| 64 | + test('should work when no variable name passed to `var()`', 'empty-var-func'); |
69 | 65 |
|
70 | 66 |
|
| 67 | + test('should work with variables declared in root', 'root-variable'); |
71 | 68 |
|
72 |
| - it('should work with descendant selector type "nesting"', function() { |
73 |
| - return testPlugin('./test/fixtures/descendant-selector.css', './test/fixtures/descendant-selector.expected.css'); |
74 |
| - }); |
| 69 | + test('should work with locally scoped variable in a non-root rule', 'local-variable-non-root'); |
75 | 70 |
|
76 |
| - it('should work with css4 descendant selector type "nesting"', function() { |
77 |
| - return testPlugin('./test/fixtures/css4-descendant-selector.css', './test/fixtures/css4-descendant-selector.expected.css'); |
78 |
| - }); |
79 | 71 |
|
| 72 | + test( |
| 73 | + 'should work with any combinator selector if the last piece is the variable we have in the map', |
| 74 | + 'scope-last-piece-of-combinator-sequence' |
| 75 | + ); |
80 | 76 |
|
81 | 77 |
|
82 |
| - it('should work with direct descendant selector', function() { |
83 |
| - return testPlugin('./test/fixtures/direct-descendant-selector.css', './test/fixtures/direct-descendant-selector.expected.css'); |
84 |
| - }); |
| 78 | + test('should work with descendant selector type "nesting"', 'descendant-selector'); |
| 79 | + test('should work with css4 descendant selector type "nesting"', 'css4-descendant-selector'); |
| 80 | + test('should work with direct descendant selector', 'direct-descendant-selector'); |
85 | 81 |
|
86 |
| - it('should work with direct descendant selector where variables are scoped in a descendant selector', function() { |
87 |
| - return testPlugin('./test/fixtures/direct-descendant-selector-descendant-scope.css', './test/fixtures/direct-descendant-selector-descendant-scope.expected.css'); |
88 |
| - }); |
| 82 | + test( |
| 83 | + 'should work with direct descendant selector where variables are scoped in a descendant selector', |
| 84 | + 'direct-descendant-selector-descendant-scope' |
| 85 | + ); |
| 86 | + test( |
| 87 | + 'should work with direct descendant selector where variables are scoped in a direct descendant selector', |
| 88 | + 'direct-descendant-selector-direct-descendant-scope' |
| 89 | + ); |
89 | 90 |
|
90 |
| - it('should work with direct descendant selector where variables are scoped in a direct descendant selector', function() { |
91 |
| - return testPlugin('./test/fixtures/direct-descendant-selector-direct-descendant-scope.css', './test/fixtures/direct-descendant-selector-direct-descendant-scope.expected.css'); |
92 |
| - }); |
93 | 91 |
|
| 92 | + test('should work with pseudo selectors', 'pseudo-selector'); |
| 93 | + test('should work with variables declared in pseudo selectors', 'pseudo-selector-declare-variable'); |
94 | 94 |
|
95 |
| - it('should work with pseudo selectors', function() { |
96 |
| - return testPlugin('./test/fixtures/pseudo-selector.css', './test/fixtures/pseudo-selector.expected.css'); |
97 |
| - }); |
98 | 95 |
|
99 |
| - it('should work with variables declared in pseudo selectors', function() { |
100 |
| - return testPlugin('./test/fixtures/pseudo-selector-declare-variable.css', './test/fixtures/pseudo-selector-declare-variable.expected.css'); |
101 |
| - }); |
102 | 96 |
|
| 97 | + test('should work with variables defined in comma separated selector', 'comma-separated-variable-declaration'); |
103 | 98 |
|
104 | 99 |
|
105 |
| - it('should work with variables defined in comma separated selector', function() { |
106 |
| - return testPlugin('./test/fixtures/comma-separated-variable-declaration.css', './test/fixtures/comma-separated-variable-declaration.expected.css'); |
107 |
| - }); |
| 100 | + test('should work use the correct variable in comma separated selector', 'comma-separated-variable-usage'); |
108 | 101 |
|
109 |
| - it('should work use the correct variable in comma separated selector', function() { |
110 |
| - return testPlugin('./test/fixtures/comma-separated-variable-usage.css', './test/fixtures/comma-separated-variable-usage.expected.css'); |
111 |
| - }); |
112 | 102 |
|
| 103 | + test('should work with star selector', 'star-selector-scope'); |
113 | 104 |
|
114 |
| - |
115 |
| - it('should work with star selector', function() { |
116 |
| - return testPlugin('./test/fixtures/star-selector-scope.css', './test/fixtures/star-selector-scope.expected.css'); |
117 |
| - }); |
118 |
| - |
119 |
| - it('should work with `!important` variable declarations', function() { |
120 |
| - return testPlugin('./test/fixtures/important-variable-declaration.css', './test/fixtures/important-variable-declaration.expected.css'); |
121 |
| - }); |
| 105 | + test('should work with `!important` variable declarations', 'important-variable-declaration'); |
122 | 106 |
|
123 | 107 |
|
124 | 108 |
|
125 | 109 | describe('with at-rules', function() {
|
126 |
| - it('should add rule declaration of property in @media', function() { |
127 |
| - return testPlugin('./test/fixtures/media-query.css', './test/fixtures/media-query.expected.css'); |
128 |
| - }); |
129 |
| - it('should add rule declaration of property in @support', function() { |
130 |
| - return testPlugin('./test/fixtures/support-directive.css', './test/fixtures/support-directive.expected.css'); |
131 |
| - }); |
| 110 | + test('should add rule declaration of property in @media', 'media-query'); |
| 111 | + test('should add rule declaration of property in @support', 'support-directive'); |
132 | 112 |
|
133 |
| - it('should work with nested @media', function() { |
134 |
| - return testPlugin('./test/fixtures/media-query-nested.css', './test/fixtures/media-query-nested.expected.css'); |
135 |
| - }); |
| 113 | + test('should work with nested @media', 'media-query-nested'); |
136 | 114 |
|
137 |
| - it('should cascade to nested rules', function() { |
138 |
| - return testPlugin('./test/fixtures/cascade-on-nested-rules.css', './test/fixtures/cascade-on-nested-rules.expected.css'); |
139 |
| - }); |
| 115 | + test('should cascade to nested rules', 'cascade-on-nested-rules'); |
140 | 116 |
|
141 |
| - it('should cascade with calc-expression to nested rules', function() { |
142 |
| - return testPlugin('./test/fixtures/cascade-with-calc-expression-on-nested-rules.css', './test/fixtures/cascade-with-calc-expression-on-nested-rules.expected.css'); |
143 |
| - }); |
| 117 | + test('should cascade with calc-expression to nested rules', 'cascade-with-calc-expression-on-nested-rules'); |
144 | 118 |
|
145 |
| - it('should cascade to nested rules in the proper scope. See issue #2', function() { |
146 |
| - return testPlugin('./test/fixtures/cascade-on-nested-rules-in-proper-scope.css', './test/fixtures/cascade-on-nested-rules-in-proper-scope.expected.css'); |
147 |
| - }); |
148 |
| - |
| 119 | + test('should cascade to nested rules in the proper scope. See issue #2', 'cascade-on-nested-rules-in-proper-scope'); |
149 | 120 | });
|
150 | 121 |
|
151 | 122 |
|
152 |
| - it('should work with variables that reference other variables', function() { |
153 |
| - return testPlugin('./test/fixtures/variable-reference-other-variable.css', './test/fixtures/variable-reference-other-variable.expected.css'); |
154 |
| - }); |
| 123 | + test('should work with variables that reference other variables', 'variable-reference-other-variable'); |
155 | 124 |
|
156 |
| - it('should work with variable with calc-expression that reference other variables', function() { |
157 |
| - return testPlugin('./test/fixtures/variable-with-calc-expression-reference-other-variable.css', './test/fixtures/variable-with-calc-expression-reference-other-variable.expected.css'); |
158 |
| - }); |
| 125 | + test( |
| 126 | + 'should work with variable with calc-expression that reference other variables', |
| 127 | + 'variable-with-calc-expression-reference-other-variable' |
| 128 | + ); |
159 | 129 |
|
160 |
| - it('should work with variables that reference other variables with at-rule changing the value', function() { |
161 |
| - return testPlugin('./test/fixtures/variable-reference-other-variable-media-query1.css', './test/fixtures/variable-reference-other-variable-media-query1.expected.css'); |
162 |
| - }); |
| 130 | + test( |
| 131 | + 'should work with variables that reference other variables with at-rule changing the value', |
| 132 | + 'variable-reference-other-variable-media-query1' |
| 133 | + ); |
| 134 | + test( |
| 135 | + 'should work with local variables that reference other variables with at-rule changing the value', |
| 136 | + 'variable-reference-other-variable-media-query2' |
| 137 | + ); |
163 | 138 |
|
164 |
| - it('should work with local variables that reference other variables with at-rule changing the value', function() { |
165 |
| - return testPlugin('./test/fixtures/variable-reference-other-variable-media-query2.css', './test/fixtures/variable-reference-other-variable-media-query2.expected.css'); |
166 |
| - }); |
167 | 139 |
|
168 | 140 |
|
169 |
| - |
170 |
| - it('should work with variables that try to self reference', function() { |
171 |
| - return testPlugin('./test/fixtures/self-reference.css', './test/fixtures/self-reference.expected.css'); |
172 |
| - }); |
173 |
| - it('should work with variables that try to self reference and fallback properly', function() { |
174 |
| - return testPlugin('./test/fixtures/self-reference-fallback.css', './test/fixtures/self-reference-fallback.expected.css'); |
175 |
| - }); |
176 |
| - |
177 |
| - it('should work with circular reference', function() { |
178 |
| - return testPlugin('./test/fixtures/circular-reference.css', './test/fixtures/circular-reference.expected.css'); |
179 |
| - }); |
180 |
| - |
| 141 | + test('should work with variables that try to self reference', 'self-reference'); |
| 142 | + test('should work with variables that try to self reference and fallback properly', 'self-reference-fallback'); |
| 143 | + test('should work with circular reference', 'circular-reference'); |
181 | 144 |
|
182 | 145 |
|
183 | 146 | describe('with `options.variables`', function() {
|
184 |
| - it('should work with JS defined variables', function() { |
185 |
| - return testPlugin( |
186 |
| - './test/fixtures/js-defined.css', |
187 |
| - './test/fixtures/js-defined.expected.css', |
188 |
| - { |
189 |
| - variables: { |
190 |
| - '--js-defined1': '75px', |
191 |
| - '--js-defined2': { |
192 |
| - value: '80px' |
193 |
| - }, |
194 |
| - // Should be automatically prefixed with `--` |
195 |
| - 'js-defined-no-prefix': '#ff0000' |
196 |
| - } |
| 147 | + test( |
| 148 | + 'should work with JS defined variables', |
| 149 | + 'js-defined', |
| 150 | + { |
| 151 | + variables: { |
| 152 | + '--js-defined1': '75px', |
| 153 | + '--js-defined2': { |
| 154 | + value: '80px' |
| 155 | + }, |
| 156 | + // Should be automatically prefixed with `--` |
| 157 | + 'js-defined-no-prefix': '#ff0000' |
197 | 158 | }
|
198 |
| - ); |
199 |
| - }); |
| 159 | + } |
| 160 | + ); |
200 | 161 | });
|
201 | 162 |
|
202 | 163 |
|
203 | 164 | describe('with `options.preserve`', function() {
|
204 |
| - it('preserves variables when `preserve` is `true`', function() { |
205 |
| - return testPlugin('./test/fixtures/preserve-variables.css', './test/fixtures/preserve-variables.expected.css', { preserve: true }); |
206 |
| - }); |
| 165 | + test( |
| 166 | + 'preserves variables when `preserve` is `true`', |
| 167 | + 'preserve-variables', |
| 168 | + { preserve: true } |
| 169 | + ); |
207 | 170 |
|
208 |
| - it('preserves computed value when `preserve` is `\'computed\'`', function() { |
209 |
| - return testPlugin('./test/fixtures/preserve-computed.css', './test/fixtures/preserve-computed.expected.css', { preserve: 'computed' }); |
210 |
| - }); |
| 171 | + test( |
| 172 | + 'preserves computed value when `preserve` is `\'computed\'`', |
| 173 | + 'preserve-computed', |
| 174 | + { preserve: 'computed' } |
| 175 | + ); |
211 | 176 | });
|
212 | 177 |
|
213 | 178 |
|
214 | 179 | describe('missing variable declarations', function() {
|
215 |
| - it('should work with missing variables', function() { |
216 |
| - return testPlugin('./test/fixtures/missing-variable-usage.css', './test/fixtures/missing-variable-usage.expected.css'); |
217 |
| - }); |
218 |
| - |
219 |
| - it('should use fallback value if provided with missing variables', function() { |
220 |
| - return testPlugin('./test/fixtures/missing-variable-should-fallback.css', './test/fixtures/missing-variable-should-fallback.expected.css'); |
221 |
| - }); |
| 180 | + test('should work with missing variables', 'missing-variable-usage'); |
| 181 | + test('should use fallback value if provided with missing variables', 'missing-variable-should-fallback'); |
222 | 182 | });
|
223 | 183 |
|
224 | 184 | it('should not parse malformed var() declarations', function() {
|
225 | 185 | return expect(testPlugin(
|
226 |
| - './test/fixtures/malformed-variable-usage.css', |
| 186 | + './test/fixtures/malformed-variable-usage.css', |
227 | 187 | './test/fixtures/malformed-variable-usage.expected.css'
|
228 | 188 | )
|
229 | 189 | ).to.eventually.be.rejected;
|
230 | 190 | });
|
231 | 191 |
|
232 | 192 | describe('rule clean up', function() {
|
233 |
| - it('should clean up rules if we removed variable declarations to make it empty', function() { |
234 |
| - return testPlugin('./test/fixtures/remove-empty-rules-after-variable-collection.css', './test/fixtures/remove-empty-rules-after-variable-collection.expected.css'); |
235 |
| - }); |
236 |
| - |
237 |
| - it('should clean up neseted rules if we removed variable declarations to make it empty', function() { |
238 |
| - return testPlugin('./test/fixtures/remove-nested-empty-rules-after-variable-collection.css', './test/fixtures/remove-nested-empty-rules-after-variable-collection.expected.css'); |
239 |
| - }); |
| 193 | + test( |
| 194 | + 'should clean up rules if we removed variable declarations to make it empty', |
| 195 | + 'remove-empty-rules-after-variable-collection' |
| 196 | + ); |
| 197 | + test( |
| 198 | + 'should clean up neseted rules if we removed variable declarations to make it empty', |
| 199 | + 'remove-nested-empty-rules-after-variable-collection' |
| 200 | + ); |
240 | 201 | });
|
241 | 202 |
|
242 | 203 |
|
|
0 commit comments