You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
|
5 months ago
|
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([])
|
||
|
|
})
|
||
|
|
})
|