* Extract tested component names from the test file. * Handles both #components imports and direct ~/components/ imports.
( testFileContent: string, componentMap: Map<string, string[]>, )
| 120 | * Handles both #components imports and direct ~/components/ imports. |
| 121 | */ |
| 122 | function getTestedComponents( |
| 123 | testFileContent: string, |
| 124 | componentMap: Map<string, string[]>, |
| 125 | ): Set<string> { |
| 126 | const tested = new Set<string>() |
| 127 | |
| 128 | // Match direct imports like: |
| 129 | // import ComponentName from '~/components/ComponentName.vue' |
| 130 | // import ComponentName from '~/components/subdir/ComponentName.vue' |
| 131 | const directImportRegex = /import\s+\w+\s+from\s+['"]~\/components\/([^"']+\.vue)['"]/g |
| 132 | let match |
| 133 | |
| 134 | while ((match = directImportRegex.exec(testFileContent)) !== null) { |
| 135 | tested.add(normalizeComponentPath(match[1]!)) |
| 136 | } |
| 137 | |
| 138 | // Match #components imports like: |
| 139 | // import { ComponentName, OtherComponent } from '#components' |
| 140 | const hashComponentsRegex = /import\s*\{([^}]+)\}\s*from\s*['"]#components['"]/g |
| 141 | while ((match = hashComponentsRegex.exec(testFileContent)) !== null) { |
| 142 | const importList = match[1]! |
| 143 | // Parse the import list, handling multi-line imports |
| 144 | const componentNames = importList |
| 145 | .split(',') |
| 146 | .map(name => name.trim()) |
| 147 | .filter(name => name.length > 0) |
| 148 | |
| 149 | for (const name of componentNames) { |
| 150 | // Look up the file paths from Nuxt's component map |
| 151 | const filePaths = componentMap.get(name) || [] |
| 152 | for (const filePath of filePaths) { |
| 153 | tested.add(filePath) |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return tested |
| 159 | } |
| 160 | |
| 161 | describe('a11y component test coverage', () => { |
| 162 | const componentsDir = path.join(import.meta.dirname, '../../app/components') |
no test coverage detected