import assert from 'node:assert/strict'
|
import test from 'node:test'
|
import fs from 'node:fs'
|
import path from 'node:path'
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
const projectRoot = path.resolve(__dirname, '..')
|
const srcRoot = path.join(projectRoot, 'src')
|
const iconRegistryModule = pathToFileURL(path.join(srcRoot, 'plugins', 'iconify.js')).href
|
|
function collectSourceFiles(dir) {
|
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
return entries.flatMap((entry) => {
|
const fullPath = path.join(dir, entry.name)
|
|
if (entry.isDirectory()) {
|
return collectSourceFiles(fullPath)
|
}
|
|
return /\.(vue|js)$/.test(entry.name) ? [fullPath] : []
|
})
|
}
|
|
function collectIconPrefixes() {
|
const iconPattern = /icon\s*[:=]\s*["']([a-z0-9-]+):/g
|
const prefixes = new Set()
|
|
for (const filePath of collectSourceFiles(srcRoot)) {
|
const content = fs.readFileSync(filePath, 'utf8')
|
|
for (const match of content.matchAll(iconPattern)) {
|
prefixes.add(match[1])
|
}
|
}
|
|
return [...prefixes].sort()
|
}
|
|
test('all used Iconify prefixes are mapped to local collections', async () => {
|
const { LOCAL_ICON_COLLECTIONS } = await import(iconRegistryModule)
|
const actualPrefixes = collectIconPrefixes()
|
const registeredPrefixes = Object.keys(LOCAL_ICON_COLLECTIONS).sort()
|
|
assert.deepEqual(
|
registeredPrefixes,
|
actualPrefixes,
|
`Missing local Iconify collections for: ${actualPrefixes.filter((prefix) => !registeredPrefixes.includes(prefix)).join(', ')}`
|
)
|
})
|