mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Refactor: Improve markdown test robustness with DOM parsing
This commit is contained in:
@@ -6,14 +6,13 @@ export default {
|
|||||||
// - The function should handle: headers (h1-h6), bold, italic, links, code blocks, inline code, lists (ordered/unordered), and blockquotes.
|
// - The function should handle: headers (h1-h6), bold, italic, links, code blocks, inline code, lists (ordered/unordered), and blockquotes.
|
||||||
// - Return the resulting HTML string.`,
|
// - Return the resulting HTML string.`,
|
||||||
runTest: async (parseMarkdown) => {
|
runTest: async (parseMarkdown) => {
|
||||||
const assert = {
|
|
||||||
strictEqual: (a, e, m) => { if (a !== e) throw new Error(m || `FAIL: ${a} !== ${e}`) },
|
|
||||||
};
|
|
||||||
const markdown = `# Hello World\n\nThis is **bold** and *italic*.\n\n- Item 1\n- Item 2\n\n\`\`\`js\nconst x = 5;\n\`\`\``;
|
const markdown = `# Hello World\n\nThis is **bold** and *italic*.\n\n- Item 1\n- Item 2\n\n\`\`\`js\nconst x = 5;\n\`\`\``;
|
||||||
const html = await parseMarkdown(markdown);
|
const html = await parseMarkdown(markdown);
|
||||||
if (!html.includes('<h1>') || !html.includes('<strong>') || !html.includes('<em>') || !html.includes('<ul>') || !html.includes('<code>')) {
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
throw new Error('Test Failed: HTML output missing required elements.');
|
const selectors = ['h1', 'strong', 'em', 'ul', 'code'];
|
||||||
|
const missing = selectors.find(s => !doc.querySelector(s));
|
||||||
|
if (missing) {
|
||||||
|
throw new Error(`Test Failed: HTML output missing required element: <${missing}>`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user