@@ -12,25 +12,31 @@ import {
1212 it ,
1313} from 'vitest'
1414import fetch from 'node-fetch'
15+ import fastGlob from 'fast-glob'
1516
1617const root = path . join ( __dirname , 'fixtures' )
1718let server : ViteDevServer | null = null
18- const PORT = 4000
19+ let port = 4000
1920
2021beforeAll ( async ( ) => {
2122 fs . rmSync ( path . join ( root , 'dist' ) , { recursive : true , force : true } )
2223 server = await createServer ( { configFile : path . join ( root , 'vite.config.ts' ) } )
23- await server . listen ( PORT )
24+ await server . listen ( port )
25+ // @ts -ignore
26+ port = server . httpServer ?. address ( ) . port
2427} )
2528
2629describe ( 'vite serve' , async ( ) => {
2730 it ( '__snapshots__' , async ( ) => {
28- const mainTs = await ( await fetch ( `http://localhost:${ PORT } /src/main.ts` ) ) . text ( )
29- const mainJs = fs . readFileSync ( path . join ( root , 'dist/main.js' ) , 'utf8' )
30- const mainJsSnap = fs . readFileSync ( path . join ( root , '__snapshots__/main.js' ) , 'utf8' )
31+ const files = fastGlob . sync ( '__snapshots__/**/*' , { cwd : root } )
32+ for ( const file of files ) {
33+ const response = await ( await fetch ( `http://localhost:${ port } /${ file . replace ( '__snapshots__' , 'src' ) } ` ) ) . text ( )
34+ const distFile = fs . readFileSync ( path . join ( root , file . replace ( '__snapshots__' , 'dist' ) ) , 'utf8' )
35+ const snapFile = fs . readFileSync ( path . join ( root , file ) , 'utf8' )
3136
32- expect ( mainTs ) . string
33- expect ( mainJs ) . eq ( mainJsSnap )
37+ expect ( response ) . string
38+ expect ( distFile ) . eq ( snapFile )
39+ }
3440 } )
3541} )
3642
0 commit comments