@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
33import { existsSync } from 'node:fs'
44import { join } from 'node:path'
55
6- import { codeExtract , registerTheme } from '@devup-ui/wasm'
6+ import { codeExtract , getCss } from '@devup-ui/wasm'
77import { globSync } from 'glob'
88
99import { preload } from '../preload'
@@ -30,6 +30,7 @@ vi.mock('glob', () => ({
3030vi . mock ( '@devup-ui/wasm' , ( ) => ( {
3131 codeExtract : vi . fn ( ) ,
3232 registerTheme : vi . fn ( ) ,
33+ getCss : vi . fn ( ) ,
3334} ) )
3435
3536describe ( 'preload' , ( ) => {
@@ -60,10 +61,9 @@ describe('preload', () => {
6061 const excludeRegex = / n o d e _ m o d u l e s /
6162 const libPackage = '@devup-ui/react'
6263 const singleCss = false
63- const theme = { colors : { primary : 'blue' } }
6464 const cssDir = '/output/css'
6565
66- preload ( excludeRegex , libPackage , singleCss , theme , cssDir )
66+ preload ( excludeRegex , libPackage , singleCss , cssDir )
6767
6868 expect ( globSync ) . toHaveBeenCalledWith (
6969 [ '**/*.tsx' , '**/*.ts' , '**/*.js' , '**/*.mjs' ] ,
@@ -74,22 +74,14 @@ describe('preload', () => {
7474 )
7575 } )
7676
77- it ( 'should register theme before processing files' , ( ) => {
78- const theme = { colors : { primary : 'blue' } }
79-
80- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , theme , '/output/css' )
81-
82- expect ( registerTheme ) . toHaveBeenCalledWith ( theme )
83- } )
84-
8577 it ( 'should process each collected file' , ( ) => {
8678 const files = [ 'src/App.tsx' , 'src/components/Button.tsx' , '.next/page.tsx' ]
8779 vi . mocked ( globSync ) . mockReturnValue ( files )
8880 vi . mocked ( realpathSync )
8981 . mockReturnValueOnce ( 'src/App.tsx' )
9082 . mockReturnValueOnce ( 'src/components/Button.tsx' )
9183 . mockReturnValueOnce ( '.next/page.tsx' )
92- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , { } , '/output/css' )
84+ preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , '/output/css' )
9385
9486 expect ( codeExtract ) . toHaveBeenCalledTimes ( 2 )
9587 expect ( codeExtract ) . toHaveBeenCalledWith (
@@ -114,7 +106,7 @@ describe('preload', () => {
114106 [ Symbol . dispose ] : vi . fn ( ) ,
115107 } )
116108
117- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , { } , '/output/css' )
109+ preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , '/output/css' )
118110
119111 expect ( writeFileSync ) . toHaveBeenCalledWith (
120112 join ( '/output/css' , 'styles.css' ) ,
@@ -133,10 +125,15 @@ describe('preload', () => {
133125 updatedBaseStyle : false ,
134126 [ Symbol . dispose ] : vi . fn ( ) ,
135127 } )
128+ vi . mocked ( getCss ) . mockReturnValue ( '' )
136129
137- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , { } , '/output/css' )
130+ preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , '/output/css' )
138131
139- expect ( writeFileSync ) . not . toHaveBeenCalled ( )
132+ expect ( writeFileSync ) . toHaveBeenCalledWith (
133+ join ( '/output/css' , 'devup-ui.css' ) ,
134+ '' ,
135+ 'utf-8' ,
136+ )
140137 } )
141138
142139 it ( 'should handle empty CSS content' , ( ) => {
@@ -150,7 +147,7 @@ describe('preload', () => {
150147 [ Symbol . dispose ] : vi . fn ( ) ,
151148 } )
152149
153- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , { } , '/output/css' )
150+ preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , '/output/css' )
154151
155152 expect ( writeFileSync ) . toHaveBeenCalledWith (
156153 join ( '/output/css' , 'styles.css' ) ,
@@ -170,7 +167,7 @@ describe('preload', () => {
170167 [ Symbol . dispose ] : vi . fn ( ) ,
171168 } )
172169
173- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , { } , '/output/css' )
170+ preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , '/output/css' )
174171
175172 expect ( writeFileSync ) . toHaveBeenCalledWith (
176173 join ( '/output/css' , 'styles.css' ) ,
@@ -184,7 +181,7 @@ describe('preload', () => {
184181 const singleCss = true
185182 const cssDir = '/custom/css/dir'
186183
187- preload ( / n o d e _ m o d u l e s / , libPackage , singleCss , { } , cssDir )
184+ preload ( / n o d e _ m o d u l e s / , libPackage , singleCss , cssDir )
188185
189186 expect ( codeExtract ) . toHaveBeenCalledWith (
190187 expect . stringMatching ( / A p p \. t s x $ / ) ,
@@ -221,9 +218,9 @@ describe('preload', () => {
221218 [ Symbol . dispose ] : vi . fn ( ) ,
222219 } )
223220
224- preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , { } , '/output/css' )
221+ preload ( / n o d e _ m o d u l e s / , '@devup-ui/react' , false , '/output/css' )
225222
226- expect ( writeFileSync ) . toHaveBeenCalledTimes ( 2 )
223+ expect ( writeFileSync ) . toHaveBeenCalledTimes ( 3 )
227224 expect ( writeFileSync ) . toHaveBeenCalledWith (
228225 join ( '/output/css' , 'app.css' ) ,
229226 '.app { margin: 0; }' ,
0 commit comments