@@ -39,6 +39,7 @@ describe('devupUIPlugin', () => {
3939 watchChange : expect . any ( Function ) ,
4040 enforce : 'pre' ,
4141 transform : expect . any ( Function ) ,
42+ apply : expect . any ( Function ) ,
4243 } )
4344 expect ( existsSync ) . toHaveBeenCalledWith ( devupPath )
4445 expect ( getThemeInterface ) . toHaveBeenCalledWith (
@@ -107,6 +108,14 @@ describe('devupUIPlugin', () => {
107108 } as any )
108109 ; ( plugin as any ) . transform ( 'code' , 'correct.ts' )
109110 expect ( writeFileSync ) . toBeCalledTimes ( 0 )
111+ ; ( plugin as any ) . apply ( { } , { command : 'serve' } )
112+ vi . clearAllMocks ( )
113+ vi . mocked ( codeExtract ) . mockReturnValueOnce ( {
114+ css : 'css code' ,
115+ code : 'code' ,
116+ } as any )
117+ ; ( plugin as any ) . transform ( 'code' , 'correct.ts' )
118+ expect ( writeFileSync ) . toBeCalledTimes ( 1 )
110119 } )
111120 it ( 'should not extract code' , ( ) => {
112121 const devupPath = 'devup.json'
@@ -130,6 +139,7 @@ describe('devupUIPlugin', () => {
130139 watchChange : expect . any ( Function ) ,
131140 enforce : 'pre' ,
132141 transform : expect . any ( Function ) ,
142+ apply : expect . any ( Function ) ,
133143 } )
134144 expect ( existsSync ) . toHaveBeenCalledWith ( devupPath )
135145 expect ( getThemeInterface ) . toHaveBeenCalledWith (
@@ -168,6 +178,41 @@ describe('devupUIPlugin', () => {
168178 watchChange : expect . any ( Function ) ,
169179 enforce : 'pre' ,
170180 transform : expect . any ( Function ) ,
181+ apply : expect . any ( Function ) ,
182+ } )
183+ expect ( existsSync ) . toHaveBeenCalledWith ( devupPath )
184+ expect ( getThemeInterface ) . toHaveBeenCalledWith (
185+ libPackage ,
186+ 'DevupThemeColors' ,
187+ 'DevupThemeTypography' ,
188+ 'DevupTheme' ,
189+ )
190+ expect ( readFileSync ) . toHaveBeenCalledWith ( devupPath , 'utf-8' )
191+ expect ( existsSync ) . toHaveBeenCalledWith ( interfacePath )
192+ } )
193+
194+ it ( 'should return true on apply' , ( ) => {
195+ const devupPath = 'devup.json'
196+ const interfacePath = '.df'
197+ const cssFile = join ( _dirname , 'devup-ui.css' )
198+ const libPackage = '@devup-ui/react'
199+ vi . mocked ( existsSync ) . mockReturnValueOnce ( true ) . mockReturnValueOnce ( false )
200+ vi . mocked ( getThemeInterface ) . mockReturnValue ( 'interface code' )
201+ vi . mocked ( readFileSync ) . mockReturnValueOnce ( '{"theme": {}}' )
202+ const options = {
203+ package : libPackage ,
204+ cssFile,
205+ devupPath,
206+ interfacePath,
207+ }
208+ const plugin = DevupUI ( options )
209+ expect ( plugin ) . toEqual ( {
210+ name : 'devup-ui' ,
211+ config : expect . any ( Function ) ,
212+ watchChange : expect . any ( Function ) ,
213+ enforce : 'pre' ,
214+ transform : expect . any ( Function ) ,
215+ apply : expect . any ( Function ) ,
171216 } )
172217 expect ( existsSync ) . toHaveBeenCalledWith ( devupPath )
173218 expect ( getThemeInterface ) . toHaveBeenCalledWith (
@@ -178,5 +223,6 @@ describe('devupUIPlugin', () => {
178223 )
179224 expect ( readFileSync ) . toHaveBeenCalledWith ( devupPath , 'utf-8' )
180225 expect ( existsSync ) . toHaveBeenCalledWith ( interfacePath )
226+ expect ( ( plugin as any ) . apply ( { } , { command : 'build' } ) ) . toBe ( true )
181227 } )
182228} )
0 commit comments