@@ -117,6 +117,53 @@ describe('devupUIPlugin', () => {
117117 ; ( plugin as any ) . transform ( 'code' , 'correct.ts' )
118118 expect ( writeFileSync ) . toBeCalledTimes ( 1 )
119119 } )
120+ it ( 'should transform code' , ( ) => {
121+ const devupPath = 'devup.json'
122+ const interfacePath = '.df'
123+ const cssFile = join ( _dirname , 'devup-ui.css' )
124+ const libPackage = '@devup-ui/react'
125+ vi . mocked ( existsSync ) . mockReturnValueOnce ( true ) . mockReturnValueOnce ( false )
126+ vi . mocked ( getThemeInterface ) . mockReturnValue ( 'interface code' )
127+ vi . mocked ( readFileSync ) . mockReturnValueOnce ( '{"theme": {}}' )
128+ const options = {
129+ package : libPackage ,
130+ cssFile,
131+ devupPath,
132+ interfacePath,
133+ }
134+ const plugin = DevupUI ( options )
135+ expect ( plugin ) . toEqual ( {
136+ name : 'devup-ui' ,
137+ config : expect . any ( Function ) ,
138+ watchChange : expect . any ( Function ) ,
139+ enforce : 'pre' ,
140+ transform : expect . any ( Function ) ,
141+ apply : expect . any ( Function ) ,
142+ } )
143+ expect ( existsSync ) . toHaveBeenCalledWith ( devupPath )
144+ expect ( getThemeInterface ) . toHaveBeenCalledWith (
145+ libPackage ,
146+ 'DevupThemeColors' ,
147+ 'DevupThemeTypography' ,
148+ 'DevupTheme' ,
149+ )
150+ expect ( readFileSync ) . toHaveBeenCalledWith ( devupPath , 'utf-8' )
151+ expect ( existsSync ) . toHaveBeenCalledWith ( interfacePath )
152+ vi . clearAllMocks ( )
153+ vi . mocked ( codeExtract ) . mockReturnValueOnce ( {
154+ css : 'css code' ,
155+ code : 'code' ,
156+ } as any )
157+ // eslint-disable-next-line prefer-spread
158+ ; ( plugin as any ) . apply ( null , {
159+ command : 'serve' ,
160+ } )
161+ vi . stubEnv ( 'NODE_ENV' , 'development' )
162+ expect ( ( plugin as any ) . transform ( 'code' , 'correct.ts' ) . code ) . toContain (
163+ 'document.head.appendChild' ,
164+ )
165+ expect ( writeFileSync ) . toBeCalledTimes ( 1 )
166+ } )
120167 it ( 'should not extract code' , ( ) => {
121168 const devupPath = 'devup.json'
122169 const interfacePath = '.df'
0 commit comments