Files
www/test/html-checks.test.js
T
paul 146d516f24
Deploy website / deploy (push) Successful in 24s
Refactor site generation into a modular content pipeline
2026-09-22 20:51:13 -04:00

24 lines
1015 B
JavaScript

import assert from 'node:assert/strict'
import { test } from 'node:test'
import { htmlFacts } from '../html-checks.js'
test('extracts decoded attributes regardless of quote style or order', () => {
const facts = htmlFacts(`<!doctype html><meta content='width=device-width' name='viewport'>
<a class='button' href='#a&amp;b'>Go</a><h2 id='a&amp;b'>Title</h2>
<code class='extra language-js another'>code</code>`)
assert.equal(facts.hasViewport, true)
assert.deepEqual(facts.ids, ['a&b'])
assert.deepEqual(facts.hrefs, ['#a&b'])
assert.deepEqual(facts.languages, ['js'])
})
test('ignores markup-like text in scripts and comments', () => {
const facts = htmlFacts(`<script>const example = '<a href="/missing"><i id="fake"></i>'</script>
<!-- <heading id="also-fake"></heading> -->
<meta name='robots' content='nofollow, noindex'>`)
assert.deepEqual(facts.ids, [])
assert.deepEqual(facts.hrefs, [])
assert.equal(facts.hasHeadingElement, false)
assert.equal(facts.isDraft, true)
})