Files
anwar-pi-website/web/tests/brand-assets.test.cjs
T

53 lines
2.7 KiB
JavaScript

const test = require('node:test')
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const crypto = require('node:crypto')
const root = path.resolve(__dirname, '..')
const read = p => fs.readFileSync(path.join(root, p), 'utf8')
const hash = p => crypto.createHash('sha256').update(fs.readFileSync(path.join(root, p))).digest('hex')
test('all navigation lockups use the approved outlined wordmark component', () => {
for (const file of ['topnav.tsx', 'site-menu.tsx', 'footer.tsx']) {
const source = read(`src/components/${file}`)
assert.match(source, /import BrandLogo from '\.\/brand-logo'/)
assert.match(source, /<BrandLogo \/>/)
assert.doesNotMatch(source, /className="logo-mark"/)
}
const logo = read('src/components/brand-logo.tsx')
assert.match(logo, /alt="أنور پآي"/)
assert.match(logo, /src="\/brand\/anwarpy-horizontal-light\.svg"/)
assert.match(logo, /width=\{152\}/)
})
test('SVG logo masters contain outlined artwork, not scripts or external fonts', () => {
for (const name of ['anwarpy-horizontal-light.svg', 'anwarpy-horizontal-dark.svg']) {
const svg = read(`public/brand/${name}`)
assert.match(svg, /<path/)
assert.doesNotMatch(svg, /<script|<foreignObject|<text\b|https?:\/\/[^" ]+\.(?:js|css|woff)/i)
}
assert.match(read('public/brand/anwarpy-horizontal-light.svg'), /#b08a45/)
assert.match(read('public/brand/anwarpy-horizontal-dark.svg'), /#d4b47c/)
})
test('manifest and all raster icon sizes are internally consistent', () => {
const manifest = JSON.parse(read('public/site.webmanifest'))
assert.equal(manifest.name, 'أنور پآي')
assert.equal(manifest.dir, 'rtl')
for (const [name, size] of [['favicon-16.png',16],['favicon-32.png',32],['favicon-48.png',48],['apple-touch-icon.png',180],['icon-192.png',192],['icon-512.png',512]]) {
const bytes = fs.readFileSync(path.join(root,'public',name))
assert.equal(bytes.readUInt32BE(16), size, name)
assert.equal(bytes.readUInt32BE(20), size, name)
}
for (const icon of manifest.icons) assert.ok(fs.existsSync(path.join(root,'public',icon.src)))
assert.equal(hash('src/app/icon.png'), hash('public/icon-512.png'))
})
test('browser metadata includes the supplied favicon, touch icon and manifest', () => {
const source = read('src/app/layout.tsx')
for (const url of ['/favicon.ico','/favicon.svg','/favicon-32.png','/favicon-16.png','/apple-touch-icon.png','/site.webmanifest']) assert.ok(source.includes(url), url)
assert.match(source, /themeColor: '#131519'/)
assert.match(read('public/favicon.svg'), /prefers-color-scheme:dark/)
assert.match(read('src/app/brand.css'), /width: 132px/)
})