11import postcss from 'postcss' ;
22import postcssRTLCSS from '../src' ;
3- import { PluginOptions , Mode } from '../src/@types' ;
3+ import { PluginOptions } from '../src/@types' ;
44import {
5- readCSSFile ,
6- runTests ,
7- createSnapshotFileName
5+ readCSSFile ,
6+ runTests ,
7+ createSnapshotFileName
88} from './utils' ;
99import 'jest-specific-snapshot' ;
1010
1111const BASE_NAME = 'process-declaration-plugins' ;
1212
1313runTests ( { } , ( pluginOptions : PluginOptions ) : void => {
1414
15- describe ( `[[Mode: ${ pluginOptions . mode } ]]` , ( ) : void => {
15+ describe ( `[[Mode: ${ pluginOptions . mode } ]]` , ( ) : void => {
1616
17- let input = '' ;
18-
19- beforeEach ( async ( ) : Promise < void > => {
20- input = input || await readCSSFile ( `input-${ BASE_NAME } .scss` ) ;
21- } ) ;
22-
23- it ( 'flip background by default' , ( ) : void => {
24- const output = postcss ( [ postcssRTLCSS ( pluginOptions ) ] ) . process ( input ) ;
25- expect ( output . css ) . toMatchSpecificSnapshot (
26- createSnapshotFileName ( BASE_NAME , 'flip' , pluginOptions . mode )
27- ) ;
28- expect ( output . warnings ( ) ) . toHaveLength ( 0 ) ;
29- } ) ;
17+ let input = '' ;
18+
19+ beforeEach ( async ( ) : Promise < void > => {
20+ input = input || await readCSSFile ( `input-${ BASE_NAME } .scss` ) ;
21+ } ) ;
22+
23+ it ( 'flip background by default' , ( ) : void => {
24+ const output = postcss ( [ postcssRTLCSS ( pluginOptions ) ] ) . process ( input ) ;
25+ expect ( output . css ) . toMatchSpecificSnapshot (
26+ createSnapshotFileName ( BASE_NAME , 'flip' , pluginOptions . mode )
27+ ) ;
28+ expect ( output . warnings ( ) ) . toHaveLength ( 0 ) ;
29+ } ) ;
30+
31+ it ( 'use {processDeclarationPlugins} to avoid flipping background' , ( ) : void => {
32+ const options : PluginOptions = {
33+ ...pluginOptions ,
34+ processDeclarationPlugins : [ {
35+ name : 'avoid-flipping-background' ,
36+ priority : 99 , // above the core RTLCSS plugin which has a priority value of 100
37+ processors : [ {
38+ expr : / ( b a c k g r o u n d | o b j e c t ) ( - p o s i t i o n ( - x ) ? | - i m a g e ) ? $ / i,
39+ action : ( prop : string , value : string ) => ( { prop, value} )
40+ } ]
41+ } ]
42+ } ;
43+ const output = postcss ( [ postcssRTLCSS ( options ) ] ) . process ( input ) ;
44+ expect ( output . css ) . toMatchSpecificSnapshot (
45+ createSnapshotFileName ( BASE_NAME , 'noflip' , pluginOptions . mode )
46+ ) ;
47+ expect ( output . warnings ( ) ) . toHaveLength ( 0 ) ;
48+ } ) ;
3049
31- it ( 'use {processDeclarationPlugins} to avoid flipping background' , ( ) : void => {
32- const options : PluginOptions = {
33- ...pluginOptions ,
34- processDeclarationPlugins : [ {
35- name : 'avoid-flipping-background' ,
36- priority : 99 , // above the core RTLCSS plugin which has a priority value of 100
37- processors : [ {
38- expr : / ( b a c k g r o u n d | o b j e c t ) ( - p o s i t i o n ( - x ) ? | - i m a g e ) ? $ / i,
39- action : ( prop : string , value : string ) => ( { prop, value} )
40- } ]
41- } ]
42- } ;
43- const output = postcss ( [ postcssRTLCSS ( options ) ] ) . process ( input ) ;
44- expect ( output . css ) . toMatchSpecificSnapshot (
45- createSnapshotFileName ( BASE_NAME , 'noflip' , pluginOptions . mode )
46- ) ;
47- expect ( output . warnings ( ) ) . toHaveLength ( 0 ) ;
4850 } ) ;
49-
50- } ) ;
5151
5252} ) ;
0 commit comments