Add tests for previous commit to avoid invoking Micromark parser when not needed, improve type definitions slightly (closes #1564).

This commit is contained in:
David Anson 2025-04-20 04:57:35 +00:00
parent 759c31760e
commit 92cd6d51cb
4 changed files with 112 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import { getVersion } from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
import * as cache from "../lib/cache.mjs";
import * as constants from "../lib/constants.mjs";
import rules from "../lib/rules.mjs";
import customRules from "./rules/rules.cjs";
@ -1063,6 +1064,71 @@ test("someCustomRulesHaveValidUrl", (t) => {
}
});
test("coverageForCacheMicromarkTokensWhenUndefined", (t) => {
t.plan(1);
cache.initialize(undefined);
t.is(cache.micromarkTokens().length, 0);
});
test("micromarkParseCalledWhenNeeded", (t) => new Promise((resolve) => {
t.plan(3);
/** @type {import("markdownlint").Rule} */
const markdownItRule = {
"names": [ "markdown-it-rule" ],
"description": "markdown-it rule",
"tags": [ "test" ],
"parser": "markdownit",
"function": () => {
t.true(cache.micromarkTokens().length > 0);
}
};
lintAsync({
"strings": {
"string": "# Heading\n\nText\n"
},
"config": {
"markdown-it-rule": true
},
"customRules": [ markdownItRule ],
"markdownItFactory": getMarkdownItFactory([])
}, function callback(err, actual) {
t.falsy(err);
const expected = { "string": [] };
t.deepEqual(actual, expected, "Unexpected issues.");
resolve();
});
}));
test("micromarkParseSkippedWhenNotNeeded", (t) => new Promise((resolve) => {
t.plan(3);
/** @type {import("markdownlint").Rule} */
const markdownItRule = {
"names": [ "markdown-it-rule" ],
"description": "markdown-it rule",
"tags": [ "test" ],
"parser": "markdownit",
"function": () => {
t.true(cache.micromarkTokens().length === 0);
}
};
lintAsync({
"strings": {
"string": "# Heading\n\nText\n"
},
"config": {
"default": false,
"markdown-it-rule": true
},
"customRules": [ markdownItRule ],
"markdownItFactory": getMarkdownItFactory([])
}, function callback(err, actual) {
t.falsy(err);
const expected = { "string": [] };
t.deepEqual(actual, expected, "Unexpected issues.");
resolve();
});
}));
test("markdownItPluginsSingle", (t) => new Promise((resolve) => {
t.plan(4);
lintAsync({