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 = /["']([a-z0-9-]+):([a-z0-9-]+)["']/g
|
const knownPrefixes = new Set([
|
'fluent',
|
'icon-park-outline',
|
'iconamoon',
|
'ix',
|
'line-md',
|
'ri',
|
'svg-spinners',
|
'system-uicons',
|
'vaadin'
|
])
|
const prefixes = new Set()
|
|
for (const filePath of collectSourceFiles(srcRoot)) {
|
const content = fs.readFileSync(filePath, 'utf8')
|
|
for (const [, prefix] of content.matchAll(iconPattern)) {
|
if (!knownPrefixes.has(prefix)) {
|
continue
|
}
|
|
prefixes.add(prefix)
|
}
|
}
|
|
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(', ')}`
|
)
|
})
|