* Parse .nuxt/components.d.ts to get the mapping from component names to file paths. * This uses Nuxt's actual component resolution, so we don't have to guess the naming convention. * * Returns a Map of component name -> array of file paths (relative to app/components/)
(dtsPath: string)
| 92 | * Returns a Map of component name -> array of file paths (relative to app/components/) |
| 93 | */ |
| 94 | function parseComponentsDeclaration(dtsPath: string): Map<string, string[]> { |
| 95 | const content = fs.readFileSync(dtsPath, 'utf-8') |
| 96 | const componentMap = new Map<string, string[]>() |
| 97 | |
| 98 | // Match lines like: |
| 99 | // export const ComponentName: typeof import("../app/components/Path/File.vue").default |
| 100 | const exportRegex = |
| 101 | /export const (\w+): typeof import\("\.\.\/app\/components\/([^"]+\.vue)"\)\.default/g |
| 102 | |
| 103 | let match |
| 104 | while ((match = exportRegex.exec(content)) !== null) { |
| 105 | const componentName = match[1]! |
| 106 | const filePath = normalizeComponentPath(match[2]!) |
| 107 | |
| 108 | const existing = componentMap.get(componentName) || [] |
| 109 | if (!existing.includes(filePath)) { |
| 110 | existing.push(filePath) |
| 111 | } |
| 112 | componentMap.set(componentName, existing) |
| 113 | } |
| 114 | |
| 115 | return componentMap |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Extract tested component names from the test file. |
no test coverage detected