58 lines
1.7 KiB
HTML
58 lines
1.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
|
</head>
|
|
|
|
<body>
|
|
<script type="module">
|
|
import van from "https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.5.3.min.js"
|
|
import * as Tests from '/test/units/index.js'
|
|
|
|
const kebab = str => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (x, ofs) => (ofs ? "-" : "") + x.toLowerCase())
|
|
const toCss = s => Object.entries(s).reduce((acc, [k, v]) => acc + `${kebab(k)}:${v};`, '')
|
|
|
|
const {div, ul, li, pre, p, span, h1} = van.tags
|
|
|
|
const Check = '\u2713'
|
|
const Cross = '\u2717'
|
|
const pathname = url => new URL(url).pathname
|
|
|
|
const Err = err => pre(`${pathname(err.fileName)} ${err.lineNumber}:${err.columnNumber} ${err}`)
|
|
const Item = (icon, color, item) => li({
|
|
style: `display: list-item; list-style-type: '${icon}'; color: ${color}`
|
|
}, item)
|
|
|
|
const Pass = ({description}) => Item(Check, 'green', description)
|
|
const Fail = ({description, error}) => Item(
|
|
Cross,
|
|
'red',
|
|
div(
|
|
description,
|
|
Err(error)
|
|
)
|
|
)
|
|
|
|
const Test = test => {
|
|
const result = test()
|
|
return result.success ? Pass(result) : Fail(result)
|
|
}
|
|
|
|
const Suite = (name, tests) => div(
|
|
h1(name),
|
|
ul(...tests.map(Test))
|
|
)
|
|
|
|
const App = () => div(
|
|
Object.entries(Tests)
|
|
.map(([name, tests]) => Suite(name, tests.default))
|
|
)
|
|
|
|
document.body.style = toCss({backgroundColor: '#2a2a2a', color: 'white'})
|
|
|
|
van.add(document.body, App())
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|