@@ -10,10 +10,10 @@ const fixturesPath = path.resolve(__dirname, "./fixtures");
10
10
function createPlugin ( name , processor ) {
11
11
const plugin = ( ) => ( {
12
12
postcssPlugin : name ,
13
- Once : processor
14
- } )
15
- plugin . postcss = true
16
- return plugin
13
+ Once : processor ,
14
+ } ) ;
15
+ plugin . postcss = true ;
16
+ return plugin ;
17
17
}
18
18
19
19
const cases = {
@@ -74,33 +74,35 @@ Object.keys(cases).forEach((name) => {
74
74
75
75
const plugins = [
76
76
autoprefixer ,
77
- createPlugin (
78
- 'validator-1' ,
79
- ( root ) => {
80
- if ( rootsSeenBeforePlugin . has ( root ) ) {
81
- throw new Error ( 'Plugin before ours was called multiple times.' )
82
- }
83
- rootsSeenBeforePlugin . add ( root ) ;
84
- root . prepend ( `/* validator-1-start (${ path . basename ( root . source . input . file ) } ) */` ) ;
85
- root . append ( `/* validator-1-end (${ path . basename ( root . source . input . file ) } ) */` ) ;
77
+ createPlugin ( "validator-1" , ( root ) => {
78
+ if ( rootsSeenBeforePlugin . has ( root ) ) {
79
+ throw new Error ( "Plugin before ours was called multiple times." ) ;
86
80
}
87
- ) ,
81
+ rootsSeenBeforePlugin . add ( root ) ;
82
+ root . prepend (
83
+ `/* validator-1-start (${ path . basename ( root . source . input . file ) } ) */`
84
+ ) ;
85
+ root . append (
86
+ `/* validator-1-end (${ path . basename ( root . source . input . file ) } ) */`
87
+ ) ;
88
+ } ) ,
88
89
plugin ( {
89
90
scopeBehaviour,
90
91
generateScopedName : scopedNameGenerator ,
91
92
getJSON : ( ) => { } ,
92
93
} ) ,
93
- createPlugin (
94
- 'validator-2' ,
95
- ( root ) => {
96
- if ( rootsSeenAfterPlugin . has ( root ) ) {
97
- throw new Error ( 'Plugin after ours was called multiple times.' )
98
- }
99
- rootsSeenAfterPlugin . add ( root ) ;
100
- root . prepend ( `/* validator-2-start (${ path . basename ( root . source . input . file ) } ) */` ) ;
101
- root . append ( `/* validator-2-end (${ path . basename ( root . source . input . file ) } ) */` ) ;
94
+ createPlugin ( "validator-2" , ( root ) => {
95
+ if ( rootsSeenAfterPlugin . has ( root ) ) {
96
+ throw new Error ( "Plugin after ours was called multiple times." ) ;
102
97
}
103
- ) ,
98
+ rootsSeenAfterPlugin . add ( root ) ;
99
+ root . prepend (
100
+ `/* validator-2-start (${ path . basename ( root . source . input . file ) } ) */`
101
+ ) ;
102
+ root . append (
103
+ `/* validator-2-end (${ path . basename ( root . source . input . file ) } ) */`
104
+ ) ;
105
+ } ) ,
104
106
] ;
105
107
106
108
const result = await postcss ( plugins ) . process ( source , { from : sourceFile } ) ;
@@ -252,7 +254,6 @@ it("processes localsConvention with dashes option", async () => {
252
254
} ) ;
253
255
} ) ;
254
256
255
-
256
257
it ( "processes localsConvention with function option" , async ( ) => {
257
258
const sourceFile = path . join ( fixturesPath , "in" , "camelCase.css" ) ;
258
259
const source = fs . readFileSync ( sourceFile ) . toString ( ) ;
@@ -261,17 +262,20 @@ it("processes localsConvention with function option", async () => {
261
262
if ( fs . existsSync ( jsonFile ) ) fs . unlinkSync ( jsonFile ) ;
262
263
263
264
await postcss ( [
264
- plugin ( { generateScopedName, localsConvention : ( className ) => {
265
- return className . replace ( 'camel-case' , 'cc' ) ;
266
- } } ) ,
265
+ plugin ( {
266
+ generateScopedName,
267
+ localsConvention : ( className ) => {
268
+ return className . replace ( "camel-case" , "cc" ) ;
269
+ } ,
270
+ } ) ,
267
271
] ) . process ( source , { from : sourceFile } ) ;
268
272
269
273
const json = fs . readFileSync ( jsonFile ) . toString ( ) ;
270
274
fs . unlinkSync ( jsonFile ) ;
271
275
272
276
expect ( JSON . parse ( json ) ) . toMatchObject ( {
273
277
cc : "_camelCase_camel-case" ,
274
- ' cc-extra' : "_camelCase_camel-case-extra" ,
278
+ " cc-extra" : "_camelCase_camel-case-extra" ,
275
279
FooBar : "_camelCase_FooBar" ,
276
280
} ) ;
277
281
} ) ;
@@ -383,3 +387,23 @@ it("processes exportGlobals option", async () => {
383
387
article : "_classes_article" ,
384
388
} ) ;
385
389
} ) ;
390
+
391
+ it ( "processes resolve option" , async ( ) => {
392
+ const sourceFile = path . join ( fixturesPath , "in" , "compose.resolve.css" ) ;
393
+ const source = fs . readFileSync ( sourceFile ) . toString ( ) ;
394
+ let json ;
395
+ const result = await postcss ( [
396
+ plugin ( {
397
+ generateScopedName,
398
+ resolve : async ( file ) => {
399
+ return file . replace ( / t e s t - f i x t u r e - i n / , path . dirname ( sourceFile ) ) ;
400
+ } ,
401
+ getJSON : ( _ , result ) => {
402
+ json = result ;
403
+ } ,
404
+ } ) ,
405
+ ] ) . process ( source , { from : sourceFile } ) ;
406
+
407
+ expect ( result . css ) . toMatchSnapshot ( "processes resolve option" ) ;
408
+ expect ( json ) . toMatchObject ( { "figure" : "_compose_resolve_figure _composes_a_hello" } ) ;
409
+ } ) ;
0 commit comments