1
- var test = require ( 'tape' ) ;
2
- var postcss = require ( 'postcss' ) ;
3
- var plugin = require ( './' ) ;
4
- var name = require ( './package.json' ) . name ;
1
+ 'use strict' ;
5
2
6
- var tests = [
3
+ const test = require ( 'tape' ) ;
4
+ const postcss = require ( 'postcss' ) ;
5
+ const plugin = require ( './' ) ;
6
+ const name = require ( './package.json' ) . name ;
7
+
8
+ const tests = [
7
9
{
8
10
should : 'scope selectors' ,
9
11
input : '.foobar {}' ,
@@ -157,7 +159,8 @@ var tests = [
157
159
{
158
160
should : 'localize animation with vendor prefix' ,
159
161
input : '.foo { -webkit-animation: bar; animation: bar; }' ,
160
- expected : ':local(.foo) { -webkit-animation: :local(bar); animation: :local(bar); }'
162
+ expected :
163
+ ':local(.foo) { -webkit-animation: :local(bar); animation: :local(bar); }'
161
164
} ,
162
165
{
163
166
should : 'not localize other rules' ,
@@ -171,23 +174,29 @@ var tests = [
171
174
} ,
172
175
{
173
176
should : 'handle a complex animation rule' ,
174
- input : '.foo { animation: foo, bar 5s linear 2s infinite alternate, barfoo 1s; }' ,
175
- expected : ':local(.foo) { animation: :local(foo), :local(bar) 5s linear 2s infinite alternate, :local(barfoo) 1s; }'
177
+ input :
178
+ '.foo { animation: foo, bar 5s linear 2s infinite alternate, barfoo 1s; }' ,
179
+ expected :
180
+ ':local(.foo) { animation: :local(foo), :local(bar) 5s linear 2s infinite alternate, :local(barfoo) 1s; }'
176
181
} ,
177
182
{
178
183
should : 'handle animations where the first value is not the animation name' ,
179
184
input : '.foo { animation: 1s foo; }' ,
180
185
expected : ':local(.foo) { animation: 1s :local(foo); }'
181
186
} ,
182
187
{
183
- should : 'handle animations where the first value is not the animation name whilst also using keywords' ,
188
+ should :
189
+ 'handle animations where the first value is not the animation name whilst also using keywords' ,
184
190
input : '.foo { animation: 1s normal ease-out infinite foo; }' ,
185
- expected : ':local(.foo) { animation: 1s normal ease-out infinite :local(foo); }'
191
+ expected :
192
+ ':local(.foo) { animation: 1s normal ease-out infinite :local(foo); }'
186
193
} ,
187
194
{
188
195
should : 'handle animations with custom timing functions' ,
189
- input : '.foo { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) foo; }' ,
190
- expected : ':local(.foo) { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) :local(foo); }'
196
+ input :
197
+ '.foo { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) foo; }' ,
198
+ expected :
199
+ ':local(.foo) { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) :local(foo); }'
191
200
} ,
192
201
{
193
202
should : 'handle animations whose names are keywords' ,
@@ -202,7 +211,8 @@ var tests = [
202
211
{
203
212
should : 'handle "constructor" as animation name' ,
204
213
input : '.foo { animation: constructor constructor; }' ,
205
- expected : ':local(.foo) { animation: :local(constructor) :local(constructor); }'
214
+ expected :
215
+ ':local(.foo) { animation: :local(constructor) :local(constructor); }'
206
216
} ,
207
217
{
208
218
should : 'default to global when mode provided' ,
@@ -247,7 +257,8 @@ var tests = [
247
257
{
248
258
should : 'localize keyframes' ,
249
259
input : '@keyframes foo { from { color: red; } to { color: blue; } }' ,
250
- expected : '@keyframes :local(foo) { from { color: red; } to { color: blue; } }'
260
+ expected :
261
+ '@keyframes :local(foo) { from { color: red; } to { color: blue; } }'
251
262
} ,
252
263
{
253
264
should : 'localize keyframes in global default mode' ,
@@ -257,8 +268,10 @@ var tests = [
257
268
} ,
258
269
{
259
270
should : 'localize explicit keyframes' ,
260
- input : '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes :global(bar) { from { color: red; } to { color: blue; } }' ,
261
- expected : '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes bar { from { color: red; } to { color: blue; } }'
271
+ input :
272
+ '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes :global(bar) { from { color: red; } to { color: blue; } }' ,
273
+ expected :
274
+ '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes bar { from { color: red; } to { color: blue; } }'
262
275
} ,
263
276
{
264
277
should : 'ignore :export statements' ,
@@ -274,7 +287,8 @@ var tests = [
274
287
should : 'compile in pure mode' ,
275
288
input : ':global(.foo).bar, [type="radio"] ~ .label, :not(.foo), #bar {}' ,
276
289
options : { mode : 'pure' } ,
277
- expected : '.foo:local(.bar), [type="radio"] ~ :local(.label), :not(:local(.foo)), :local(#bar) {}'
290
+ expected :
291
+ '.foo:local(.bar), [type="radio"] ~ :local(.label), :not(:local(.foo)), :local(#bar) {}'
278
292
} ,
279
293
{
280
294
should : 'compile explict global element' ,
@@ -381,16 +395,19 @@ var tests = [
381
395
} ,
382
396
{
383
397
should : 'not modify urls without option' ,
384
- input : '.a { background: url(./image.png); }\n' +
398
+ input :
399
+ '.a { background: url(./image.png); }\n' +
385
400
':global .b { background: url(image.png); }\n' +
386
401
'.c { background: url("./image.png"); }' ,
387
- expected : ':local(.a) { background: url(./image.png); }\n' +
402
+ expected :
403
+ ':local(.a) { background: url(./image.png); }\n' +
388
404
'.b { background: url(image.png); }\n' +
389
405
':local(.c) { background: url("./image.png"); }'
390
406
} ,
391
407
{
392
408
should : 'rewrite url in local block' ,
393
- input : '.a { background: url(./image.png); }\n' +
409
+ input :
410
+ '.a { background: url(./image.png); }\n' +
394
411
':global .b { background: url(image.png); }\n' +
395
412
'.c { background: url("./image.png"); }\n' +
396
413
'.d { background: -webkit-image-set(url("./image.png") 1x, url("./image2x.png") 2x); }\n' +
@@ -401,16 +418,17 @@ var tests = [
401
418
'@keyframes ani2 { 0% { src: url("./image.png"); } }' ,
402
419
options : {
403
420
rewriteUrl : function ( global , url ) {
404
- var mode = global ? 'global' : 'local' ;
421
+ const mode = global ? 'global' : 'local' ;
405
422
return '(' + mode + ')' + url + '"' + mode + '"' ;
406
423
}
407
424
} ,
408
- expected : ':local(.a) { background: url((local\\)./image.png\\\"local\\\"); }\n' +
409
- '.b { background: url((global\\)image.png\\\"global\\\"); }\n' +
410
- ':local(.c) { background: url(\"(local)./image.png\\\"local\\\"\"); }\n' +
411
- ':local(.d) { background: -webkit-image-set(url(\"(local)./image.png\\\"local\\\"\") 1x, url(\"(local)./image2x.png\\\"local\\\"\") 2x); }\n' +
412
- '@font-face { src: url(\"(local)./font.woff\\\"local\\\"\"); }\n' +
413
- '@-webkit-font-face { src: url(\"(local)./font.woff\\\"local\\\"\"); }\n' +
425
+ expected :
426
+ ':local(.a) { background: url((local\\)./image.png\\"local\\"); }\n' +
427
+ '.b { background: url((global\\)image.png\\"global\\"); }\n' +
428
+ ':local(.c) { background: url("(local)./image.png\\"local\\""); }\n' +
429
+ ':local(.d) { background: -webkit-image-set(url("(local)./image.png\\"local\\"") 1x, url("(local)./image2x.png\\"local\\"") 2x); }\n' +
430
+ '@font-face { src: url("(local)./font.woff\\"local\\""); }\n' +
431
+ '@-webkit-font-face { src: url("(local)./font.woff\\"local\\""); }\n' +
414
432
'@media screen { :local(.a) { src: url("(local)./image.png\\"local\\""); } }\n' +
415
433
'@keyframes ani1 { 0% { src: url("(global)image.png\\"global\\""); } }\n' +
416
434
'@keyframes :local(ani2) { 0% { src: url("(local)./image.png\\"local\\""); } }'
@@ -423,40 +441,46 @@ var tests = [
423
441
{
424
442
should : 'not crash on a rule without nodes' ,
425
443
input : ( function ( ) {
426
- var inner = postcss . rule ( { selector : '.b' , ruleWithoutBody : true } ) ;
427
- var outer = postcss . rule ( { selector : '.a' } ) . push ( inner ) ;
428
- var root = postcss . root ( ) . push ( outer ) ;
444
+ const inner = postcss . rule ( { selector : '.b' , ruleWithoutBody : true } ) ;
445
+ const outer = postcss . rule ( { selector : '.a' } ) . push ( inner ) ;
446
+ const root = postcss . root ( ) . push ( outer ) ;
429
447
inner . nodes = undefined ;
430
448
return root ;
431
449
} ) ( ) ,
432
450
// postcss-less's stringify would honor `ruleWithoutBody` and omit the trailing `{}`
433
451
expected : ':local(.a) {\n :local(.b) {}\n}'
434
452
}
435
-
436
453
] ;
437
454
438
- function process ( css , options ) {
439
- return postcss ( plugin ( options ) ) . process ( css ) . css ;
455
+ function process ( css , options ) {
456
+ return postcss ( plugin ( options ) ) . process ( css ) . css ;
440
457
}
441
458
442
- test ( name , function ( t ) {
443
- t . plan ( tests . length ) ;
459
+ test ( name , function ( t ) {
460
+ t . plan ( tests . length ) ;
444
461
445
- tests . forEach ( function ( testCase ) {
446
- var options = testCase . options ;
447
- if ( testCase . error ) {
448
- t . throws ( function ( ) {
449
- process ( testCase . input , options ) ;
450
- } , testCase . error , 'should ' + testCase . should ) ;
451
- } else {
452
- t . equal ( process ( testCase . input , options ) , testCase . expected , 'should ' + testCase . should ) ;
453
- }
454
- } ) ;
462
+ tests . forEach ( function ( testCase ) {
463
+ const options = testCase . options ;
464
+ if ( testCase . error ) {
465
+ t . throws (
466
+ function ( ) {
467
+ process ( testCase . input , options ) ;
468
+ } ,
469
+ testCase . error ,
470
+ 'should ' + testCase . should
471
+ ) ;
472
+ } else {
473
+ t . equal (
474
+ process ( testCase . input , options ) ,
475
+ testCase . expected ,
476
+ 'should ' + testCase . should
477
+ ) ;
478
+ }
479
+ } ) ;
455
480
} ) ;
456
481
457
-
458
- test ( 'should use the postcss plugin api' , function ( t ) {
459
- t . plan ( 2 ) ;
460
- t . ok ( plugin ( ) . postcssVersion , 'should be able to access version' ) ;
461
- t . equal ( plugin ( ) . postcssPlugin , name , 'should be able to access name' ) ;
482
+ test ( 'should use the postcss plugin api' , function ( t ) {
483
+ t . plan ( 2 ) ;
484
+ t . ok ( plugin ( ) . postcssVersion , 'should be able to access version' ) ;
485
+ t . equal ( plugin ( ) . postcssPlugin , name , 'should be able to access name' ) ;
462
486
} ) ;
0 commit comments