@@ -3791,3 +3791,78 @@ describe('prefix()', () => {
3791
3791
expect ( fn ) . toHaveBeenCalledWith ( 'btn' )
3792
3792
} )
3793
3793
} )
3794
+
3795
+ describe ( 'config()' , ( ) => {
3796
+ test ( 'can return the resolved config when passed no arguments' , async ( ) => {
3797
+ let fn = vi . fn ( )
3798
+ await compile (
3799
+ css `
3800
+ @plugin "my-plugin" ;
3801
+ ` ,
3802
+ {
3803
+ async loadModule ( id , base ) {
3804
+ return {
3805
+ base,
3806
+ module : ( { config } : PluginAPI ) => {
3807
+ fn ( config ( ) )
3808
+ } ,
3809
+ }
3810
+ } ,
3811
+ } ,
3812
+ )
3813
+
3814
+ expect ( fn ) . toHaveBeenCalledWith (
3815
+ expect . objectContaining ( {
3816
+ theme : expect . objectContaining ( {
3817
+ spacing : expect . any ( Object ) ,
3818
+ } ) ,
3819
+ } ) ,
3820
+ )
3821
+ } )
3822
+
3823
+ test ( 'can return part of the config' , async ( ) => {
3824
+ let fn = vi . fn ( )
3825
+ await compile (
3826
+ css `
3827
+ @plugin "my-plugin" ;
3828
+ ` ,
3829
+ {
3830
+ async loadModule ( id , base ) {
3831
+ return {
3832
+ base,
3833
+ module : ( { config } : PluginAPI ) => {
3834
+ fn ( config ( 'theme' ) )
3835
+ } ,
3836
+ }
3837
+ } ,
3838
+ } ,
3839
+ )
3840
+
3841
+ expect ( fn ) . toHaveBeenCalledWith (
3842
+ expect . objectContaining ( {
3843
+ spacing : expect . any ( Object ) ,
3844
+ } ) ,
3845
+ )
3846
+ } )
3847
+
3848
+ test ( 'falls back to default value if requested path does not exist' , async ( ) => {
3849
+ let fn = vi . fn ( )
3850
+ await compile (
3851
+ css `
3852
+ @plugin "my-plugin" ;
3853
+ ` ,
3854
+ {
3855
+ async loadModule ( id , base ) {
3856
+ return {
3857
+ base,
3858
+ module : ( { config } : PluginAPI ) => {
3859
+ fn ( config ( 'somekey' , 'defaultvalue' ) )
3860
+ } ,
3861
+ }
3862
+ } ,
3863
+ } ,
3864
+ )
3865
+
3866
+ expect ( fn ) . toHaveBeenCalledWith ( 'defaultvalue' )
3867
+ } )
3868
+ } )
0 commit comments