Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 23 additions & 1 deletion test/run-tests.test.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
],
},
},
});
});
});