diff --git a/src/run-tests.ts b/src/run-tests.ts index ee9e084..5ba9a7a 100644 --- a/src/run-tests.ts +++ b/src/run-tests.ts @@ -64,18 +64,22 @@ export async function runTests({ const before = process.hrtime(); const parsed = await parse(test.markdown, options, addExtension); const elapsed = process.hrtime(before); - const pass = isEqual(parsed, test.html); - if (test.shouldFail) { + if (options.renderOk) { assert.ok( - !pass, - `${test.markdown}\n------\n\nExpected: Should Fail`, + parsed, + `${test.markdown}\n------\n\nExpected: To Render Anything`, ); } else if (options.renderExact) { - assert.strictEqual(test.html, parsed); + assert.strictEqual(test.html ?? "", parsed); + } else if (test.shouldFail) { + assert.ok( + !isEqual(parsed, test.html ?? ""), + `${test.markdown}\n------\n\nExpected: Should Fail`, + ); } else { - const testDiff = diff(parsed, test.html); + const testDiff = diff(parsed, test.html ?? ""); assert.ok( - pass, + isEqual(parsed, test.html ?? ""), `Expected: ${testDiff.expected}\n Actual: ${testDiff.actual}`, ); } diff --git a/src/types.ts b/src/types.ts index 7e2947f..8af290e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,9 +3,10 @@ import { MarkedExtension } from "marked"; export interface Spec { section: string; markdown: string; - html: string; + html?: string; options?: MarkedExtension & { renderExact?: boolean; + renderOk?: boolean; }; only?: boolean; skip?: boolean; diff --git a/test/run-tests.test.ts b/test/run-tests.test.ts index ebde81d..a251fd0 100644 --- a/test/run-tests.test.ts +++ b/test/run-tests.test.ts @@ -1,8 +1,30 @@ -import { runAllMarkedSpecTests } from "../src/index.js"; +import { runAllMarkedSpecTests, runTests } from "../src/index.js"; import test from "node:test"; +import assert from "node:assert"; test("run-tests", async (t) => { await t.test("runAllMarkedSpecTests", async () => { await runAllMarkedSpecTests(); }); + + await t.test("renderOk option", async () => { + // This test should pass because renderOk is true even though html does not match the actual parsed output. + await runTests({ + tests: { + "Render OK Section": { + total: 1, + pass: 1, + specs: [ + { + section: "Render OK Section", + markdown: "hello", + options: { + renderOk: true, + }, + }, + ], + }, + }, + }); + }); });