test / rich-content.test.js
import { test } from "node:test";
import assert from "node:assert/strict";
import { parseRss, extractReadable } from "../lib/parser.js";
import { createLogger, getOrCreateOperationId } from "../lib/log.js";
test("Atom XHTML retains headings, mixed text, and summary fallback", () => {
const xml = `<feed xmlns="http://www.w3.org/2005/Atom"><entry><id>1</id><title>Example</title>
<summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Summary <b>words</b> here.</p></div></summary>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><h2>Details</h2><p>Before <b>bold</b> after.</p><script>ignore me</script></div></content>
</entry><entry><id>2</id><title>Fallback</title><summary>Only summary</summary></entry></feed>`;
const items = parseRss(xml, "https://example.com/feed");
assert.match(items[0].content, /## Details/);
assert.match(items[0].content, /Before bold after\./);
assert.doesNotMatch(items[0].content, /ignore me/);
assert.match(items[0].summary, /Summary words here/);
assert.equal(items[1].content, "Only summary");
});
test("article extraction excludes executable content", () => {
assert.equal(extractReadable("<article><h2>Heading</h2><p>Readable text.</p><script>hidden()</script></article>"), "## Heading\n\nReadable text.");
});
test("logging preserves error details and gives each operation a unique ID", () => {
const oldWrite = process.stderr.write;
const lines = [];
process.stderr.write = (line) => { lines.push(line); return true; };
try {
createLogger("test").error("indexing-failed", "disk full");
} finally {
process.stderr.write = oldWrite;
}
const event = JSON.parse(lines[0]);
assert.equal(event.detail, "disk full");
assert.equal(event.component, "test");
assert.notEqual(getOrCreateOperationId("search"), getOrCreateOperationId("search"));
});
test / rich-content.test.js
import { test } from "node:test";
import assert from "node:assert/strict";
import { parseRss, extractReadable } from "../lib/parser.js";
import { createLogger, getOrCreateOperationId } from "../lib/log.js";
test("Atom XHTML retains headings, mixed text, and summary fallback", () => {
const xml = `<feed xmlns="http://www.w3.org/2005/Atom"><entry><id>1</id><title>Example</title>
<summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Summary <b>words</b> here.</p></div></summary>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><h2>Details</h2><p>Before <b>bold</b> after.</p><script>ignore me</script></div></content>
</entry><entry><id>2</id><title>Fallback</title><summary>Only summary</summary></entry></feed>`;
const items = parseRss(xml, "https://example.com/feed");
assert.match(items[0].content, /## Details/);
assert.match(items[0].content, /Before bold after\./);
assert.doesNotMatch(items[0].content, /ignore me/);
assert.match(items[0].summary, /Summary words here/);
assert.equal(items[1].content, "Only summary");
});
test("article extraction excludes executable content", () => {
assert.equal(extractReadable("<article><h2>Heading</h2><p>Readable text.</p><script>hidden()</script></article>"), "## Heading\n\nReadable text.");
});
test("logging preserves error details and gives each operation a unique ID", () => {
const oldWrite = process.stderr.write;
const lines = [];
process.stderr.write = (line) => { lines.push(line); return true; };
try {
createLogger("test").error("indexing-failed", "disk full");
} finally {
process.stderr.write = oldWrite;
}
const event = JSON.parse(lines[0]);
assert.equal(event.detail, "disk full");
assert.equal(event.component, "test");
assert.notEqual(getOrCreateOperationId("search"), getOrCreateOperationId("search"));
});