@@ -1198,22 +1198,28 @@ export const isNonDriveRelativeAbsolutePath = (p: string): boolean => {
1198
1198
* consistent behaviour between dev and prod and across operating systems.
1199
1199
*/
1200
1200
export function shouldServe ( url : string , assetsDir : string ) : boolean {
1201
- // viteTestUrl is set to something like http://localhost:4173/ and then many tests make calls
1202
- // like `await page.goto(viteTestUrl + '/example')` giving us URLs beginning with a double slash
1203
- const pathname = decodeURI (
1204
- new URL ( url . startsWith ( '//' ) ? url . substring ( 1 ) : url , 'http://example.com' )
1205
- . pathname
1206
- )
1207
- const file = path . join ( assetsDir , pathname )
1208
- if (
1209
- ! fs . existsSync ( file ) ||
1210
- ( isCaseInsensitiveFS && // can skip case check on Linux
1211
- ! fs . statSync ( file ) . isDirectory ( ) &&
1212
- ! hasCorrectCase ( file , assetsDir ) )
1213
- ) {
1201
+ try {
1202
+ // viteTestUrl is set to something like http://localhost:4173/ and then many tests make calls
1203
+ // like `await page.goto(viteTestUrl + '/example')` giving us URLs beginning with a double slash
1204
+ const pathname = decodeURI (
1205
+ new URL (
1206
+ url . startsWith ( '//' ) ? url . substring ( 1 ) : url ,
1207
+ 'http://example.com'
1208
+ ) . pathname
1209
+ )
1210
+ const file = path . join ( assetsDir , pathname )
1211
+ if (
1212
+ ! fs . existsSync ( file ) ||
1213
+ ( isCaseInsensitiveFS && // can skip case check on Linux
1214
+ ! fs . statSync ( file ) . isDirectory ( ) &&
1215
+ ! hasCorrectCase ( file , assetsDir ) )
1216
+ ) {
1217
+ return false
1218
+ }
1219
+ return true
1220
+ } catch ( err ) {
1214
1221
return false
1215
1222
}
1216
- return true
1217
1223
}
1218
1224
1219
1225
/**
0 commit comments