30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { marked } from "marked";
|
|
import { installLiteCompatibility } from "../src/lib/lite-compat.ts";
|
|
|
|
test("Markdown still renders on readers without native Array.at", () => {
|
|
const original = Object.getOwnPropertyDescriptor(Array.prototype, "at");
|
|
try {
|
|
delete Array.prototype.at;
|
|
installLiteCompatibility();
|
|
assert.equal([1, 2, 3].at(-1), 3);
|
|
assert.equal([1, 2, 3].at(-4), undefined);
|
|
assert.equal([1, 2, 3].at(Infinity), undefined);
|
|
assert.equal(Object.getOwnPropertyDescriptor(Array.prototype, "at").enumerable, false);
|
|
const html = marked("## A reply\n\nFirst paragraph.\n\nSecond paragraph.\n\n| Name | Value |\n| --- | --- |\n| One | Two |");
|
|
assert.match(html, /<h2>A reply<\/h2>/);
|
|
assert.match(html, /<table>/);
|
|
assert.match(html, /<td>Two<\/td>/);
|
|
} finally {
|
|
if (original) Object.defineProperty(Array.prototype, "at", original);
|
|
else delete Array.prototype.at;
|
|
}
|
|
});
|
|
|
|
test("Lite keeps the browser's existing Array.at implementation", () => {
|
|
const original = Array.prototype.at;
|
|
installLiteCompatibility();
|
|
assert.equal(Array.prototype.at, original);
|
|
});
|