parent
a8045658aa
commit
250ae7f75c
@ -0,0 +1,51 @@
|
||||
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
const COMPONENTS_DIR = 'src/uix/eidos/components'
|
||||
const ROOT_FILE_EXCEPTIONS = new Set(['svg'])
|
||||
|
||||
function stripComments(source: string): string {
|
||||
return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/.*$/gm, '$1')
|
||||
}
|
||||
|
||||
function readComponentDirs(): readonly string[] {
|
||||
return readdirSync(COMPONENTS_DIR, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => entry.name)
|
||||
.sort()
|
||||
}
|
||||
|
||||
function readIndexSource(component: string): string {
|
||||
return stripComments(readFileSync(join(COMPONENTS_DIR, component, 'index.ts'), 'utf8'))
|
||||
}
|
||||
|
||||
describe('Eidos component API contract', () => {
|
||||
it('keeps component barrels on the disciplined option C surface', () => {
|
||||
const violations: string[] = []
|
||||
|
||||
for (const component of readComponentDirs()) {
|
||||
const source = readIndexSource(component)
|
||||
|
||||
if (/\bObject\.assign\s*\(/.test(source)) {
|
||||
violations.push(`${component}: Object.assign`)
|
||||
}
|
||||
if (/export\s+(?:type\s+)?\{[^}]*\bProvider\b[^}]*\}/s.test(source)) {
|
||||
violations.push(`${component}: public Provider export`)
|
||||
}
|
||||
if (/from\s+['"]\.\/.*provider\.svelte['"]/.test(source)) {
|
||||
violations.push(`${component}: provider component import`)
|
||||
}
|
||||
}
|
||||
|
||||
expect(violations).toEqual([])
|
||||
})
|
||||
|
||||
it('keeps every public Eidos component rooted at {component}.svelte', () => {
|
||||
const missingRoots = readComponentDirs()
|
||||
.filter((component) => !ROOT_FILE_EXCEPTIONS.has(component))
|
||||
.filter((component) => !existsSync(join(COMPONENTS_DIR, component, `${component}.svelte`)))
|
||||
|
||||
expect(missingRoots).toEqual([])
|
||||
})
|
||||
})
|
||||
Loading…
Reference in new issue