LCOV - code coverage report
Current view: top level - src/utils - preloadErrorUtil.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 16.7 % 30 5
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : type PreloadFileType = 'js' | 'css' | 'font' | 'image' | 'unknown'
       2              : 
       3              : interface PreloadErrorInfo {
       4              :   url: string | null
       5              :   fileType: PreloadFileType
       6              :   chunkName: string | null
       7              :   message: string
       8              : }
       9              : 
      10         2356 : const CSS_PRELOAD_RE = /Unable to preload CSS for (.+)/
      11         2356 : const JS_DYNAMIC_IMPORT_RE =
      12              :   /Failed to fetch dynamically imported module:\s*(.+)/
      13         2356 : const URL_FALLBACK_RE = /https?:\/\/[^\s"')]+/
      14              : 
      15         2356 : const FONT_EXTENSIONS = new Set(['woff', 'woff2', 'ttf', 'otf', 'eot'])
      16         2356 : const IMAGE_EXTENSIONS = new Set([
      17              :   'png',
      18              :   'jpg',
      19              :   'jpeg',
      20              :   'gif',
      21              :   'svg',
      22              :   'webp',
      23              :   'avif',
      24              :   'ico'
      25              : ])
      26              : 
      27            0 : function extractUrl(message: string): string | null {
      28            0 :   const cssMatch = message.match(CSS_PRELOAD_RE)
      29            0 :   if (cssMatch) return cssMatch[1].trim()
      30              : 
      31            0 :   const jsMatch = message.match(JS_DYNAMIC_IMPORT_RE)
      32            0 :   if (jsMatch) return jsMatch[1].trim()
      33              : 
      34            0 :   const fallbackMatch = message.match(URL_FALLBACK_RE)
      35            0 :   if (fallbackMatch) return fallbackMatch[0]
      36              : 
      37            0 :   return null
      38              : }
      39              : 
      40            0 : function detectFileType(url: string): PreloadFileType {
      41              :   const pathname = new URL(url, 'https://cloud.comfy.org').pathname
      42            0 :   const ext = pathname.split('.').pop()?.toLowerCase()
      43            0 :   if (!ext) return 'unknown'
      44              : 
      45              :   // Strip query params from extension
      46            0 :   const cleanExt = ext.split('?')[0]
      47              : 
      48            0 :   if (cleanExt === 'js' || cleanExt === 'mjs') return 'js'
      49            0 :   if (cleanExt === 'css') return 'css'
      50            0 :   if (FONT_EXTENSIONS.has(cleanExt)) return 'font'
      51            0 :   if (IMAGE_EXTENSIONS.has(cleanExt)) return 'image'
      52            0 :   return 'unknown'
      53              : }
      54              : 
      55            0 : function extractChunkName(url: string): string | null {
      56              :   const pathname = new URL(url, 'https://cloud.comfy.org').pathname
      57            0 :   const filename = pathname.split('/').pop()
      58            0 :   if (!filename) return null
      59              : 
      60              :   // Strip extension
      61              :   const nameWithoutExt = filename.replace(/\.[^.]+$/, '')
      62              :   // Strip hash suffix (e.g. "vendor-vue-core-abc123" -> "vendor-vue-core")
      63              :   const withoutHash = nameWithoutExt.replace(/-[a-f0-9]{6,}$/, '')
      64            0 :   return withoutHash || null
      65              : }
      66              : 
      67            0 : export function parsePreloadError(error: Error): PreloadErrorInfo {
      68            0 :   const message = error.message || String(error)
      69            0 :   const url = extractUrl(message)
      70              : 
      71            0 :   return {
      72              :     url,
      73              :     fileType: url ? detectFileType(url) : 'unknown',
      74              :     chunkName: url ? extractChunkName(url) : null,
      75              :     message
      76              :   }
      77              : }
        

Generated by: LCOV version 2.0-1