MCPcopy
hub / github.com/npmx-dev/npmx.dev / getTestedComponents

Function getTestedComponents

test/unit/a11y-component-coverage.spec.ts:122–159  ·  view source on GitHub ↗

* Extract tested component names from the test file. * Handles both #components imports and direct ~/components/ imports.

(
  testFileContent: string,
  componentMap: Map<string, string[]>,
)

Source from the content-addressed store, hash-verified

120 * Handles both #components imports and direct ~/components/ imports.
121 */
122function 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
161describe('a11y component test coverage', () => {
162 const componentsDir = path.join(import.meta.dirname, '../../app/components')

Callers 1

Calls 2

normalizeComponentPathFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected