Files
StarPilot/openpilot/starpilot/galaxy/tests/test_ui_templates.mjs
T
2026-10-20 01:49:49 -04:00

28 lines
1.3 KiB
JavaScript

import assert from 'node:assert/strict'
import { readdir } from 'node:fs/promises'
import { compile } from '../web/vendor/vue/vue.esm-browser.js'
// Compile every exported component, including lazily loaded pages and nested primitives.
globalThis.location = { hash: '#/' }
const directory = new URL('../web/js/', import.meta.url)
const visited = new Set()
let count = 0
function check(component, label) {
if (!component || typeof component !== 'object' || visited.has(component)) return
visited.add(component)
if (component.template) {
const errors = []
compile(component.template, { decodeEntities: value => value.replaceAll('&', '&'), onError: error => errors.push(error.message) })
assert.deepEqual(errors, [], label)
count++
}
for (const [name, child] of Object.entries(component.components || {})) check(child, `${label}/${name}`)
}
for (const file of await readdir(directory)) {
if (!file.endsWith('.js') || ['app.js', 'boot.js', 'boot-screen.js'].includes(file)) continue
const module = await import(new URL(file, directory))
for (const [name, component] of Object.entries(module)) check(component, `${file}/${name}`)
}
assert.ok(count >= 40, `Expected the whole component inventory, got ${count}`)
console.log(`Compiled ${count} Galaxy page and shared-component templates.`)