mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add tests for previous commit to avoid invoking Micromark parser when not needed, improve type definitions slightly (closes #1564).
This commit is contained in:
parent
759c31760e
commit
92cd6d51cb
4 changed files with 112 additions and 6 deletions
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue