test(pdf): R3 oracle generators typed without the DOM lib

This commit is contained in:
bchanot committed 2026-10-14 23:59:52 +02:00
1 parent 09a6cf7def
commit 62f930c14e
2 files changed
+6 -6

No files matched your search

@@ -14,7 +14,7 @@
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { DOMParser, type Node as XmlNode } from '@xmldom/xmldom'
import { DOMParser, type Element as XmlElement, type Node as XmlNode } from '@xmldom/xmldom'
import { describe, expect, it } from 'vitest'
import type { Observation, SheetSnapshot } from '@faunosteo/domain'
import { cleanSvgRoot, renderHighlightedView } from '../src/svg/view'
@@ -36,12 +36,12 @@ function treeOf(node: XmlNode): TreeNode {
if (node.nodeType === 3 || node.nodeType === 4) return { text: node.nodeValue ?? '' }
if (node.nodeType === 8) return { comment: node.nodeValue ?? '' }
if (node.nodeType === 7) return { pi: node.nodeName }
const el = node as unknown as Element
const el = node as unknown as XmlElement
const attrs: Record<string, string> = {}
const names = Array.from({ length: el.attributes.length }, (_, i) => el.attributes[i]!.name)
for (const name of names.sort()) attrs[name] = el.getAttribute(name) ?? ''
const children = Array.from({ length: node.childNodes.length }, (_, i) => node.childNodes[i]!)
return { ns: el.namespaceURI, name: el.localName, attrs, children: children.map(treeOf) }
return { ns: el.namespaceURI, name: el.localName ?? el.nodeName, attrs, children: children.map(treeOf) }
}
const parsedTree = (svg: string) =>
@@ -13,7 +13,7 @@
import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { DOMParser, type Node as XmlNode } from '@xmldom/xmldom'
import { DOMParser, type Element as XmlElement, type Node as XmlNode } from '@xmldom/xmldom'
import { describe, expect, it } from 'vitest'
import { parseSvg, serializeSvg } from '../src/svg/parse'
import { sanitizeSvgRoot } from '../src/svg/sanitize'
@@ -98,12 +98,12 @@ function treeOf(node: XmlNode): TreeNode {
if (node.nodeType === 3 || node.nodeType === 4) return { text: node.nodeValue ?? '' }
if (node.nodeType === 8) return { comment: node.nodeValue ?? '' }
if (node.nodeType === 7) return { pi: node.nodeName }
const el = node as unknown as Element
const el = node as unknown as XmlElement
const attrs: Record<string, string> = {}
const names = Array.from({ length: el.attributes.length }, (_, i) => el.attributes[i]!.name)
for (const name of names.sort()) attrs[name] = el.getAttribute(name) ?? ''
const children = Array.from({ length: node.childNodes.length }, (_, i) => node.childNodes[i]!)
return { ns: el.namespaceURI, name: el.localName, attrs, children: children.map(treeOf) }
return { ns: el.namespaceURI, name: el.localName ?? el.nodeName, attrs, children: children.map(treeOf) }
}
type Verdict =