@tkeron/html-parser 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
- import { describe, it } from "bun:test";
1
+ import { describe, it, expect } from "bun:test";
2
2
  import { readFileSync } from "fs";
3
- import { parse } from "../src/index.ts";
3
+ import { parseHTML } from "../src/index.ts";
4
+ import { serializeToHtml5lib } from "./helpers/tree-adapter";
4
5
 
5
6
  describe("Tree Construction Html5testCom Tests", () => {
6
7
  const data = readFileSync("tests/html5lib-data/tree-construction/html5test-com.dat", "utf8");
@@ -10,15 +11,22 @@ describe("Tree Construction Html5testCom Tests", () => {
10
11
  const parts = section.split("#document\n");
11
12
  if (parts.length < 2) continue;
12
13
  const inputWithErrors = parts[0];
13
- const expected = parts[1];
14
+ const expectedRaw = parts[1].split("\n#")[0];
15
+ const expected = expectedRaw.split("\n").filter(l => l.startsWith("|")).join("\n") + "\n";
14
16
  const input = inputWithErrors.split("#errors\n")[0].trim();
17
+ const hasDoctype = input.toLowerCase().startsWith("<!doctype");
15
18
 
16
19
  const testName = input.split("\n")[0] || "Html5testCom test";
17
- it.skip(testName, () => {
18
- const doc = parse(input);
19
- // TODO: Implement DOM tree comparison with expected
20
- // For now, just ensure parsing doesn't throw
21
- expect(doc).toBeDefined();
20
+
21
+ const isFosterParenting = input.includes('<table><form><input type=hidden><input></form><div></div></table>');
22
+ const isAdoptionAgency = input.includes('<i>A<b>B<p></i>C</b>D');
23
+
24
+ const testFn = (isFosterParenting || isAdoptionAgency) ? it.skip : it;
25
+
26
+ testFn(testName, () => {
27
+ const doc = parseHTML(input);
28
+ const actual = serializeToHtml5lib(doc, { skipImplicitDoctype: !hasDoctype });
29
+ expect(actual).toBe(expected);
22
30
  });
23
31
  }
24
32
  });