@github/markdownlint-github
Version:
An opinionated collection of markdownlint rules used by GitHub.
74 lines (66 loc) • 2.35 kB
JavaScript
import { init } from "../index.js";
import { githubMarkdownLint } from "../src/rules/index.js";
describe("usage", () => {
describe("default export", () => {
test("custom rules on default export", () => {
const rules = githubMarkdownLint;
expect(rules).toHaveLength(3);
expect(rules[0].names).toEqual(["GH001", "no-default-alt-text"]);
expect(rules[1].names).toEqual(["GH002", "no-generic-link-text"]);
expect(rules[2].names).toEqual(["GH003", "no-empty-alt-text"]);
});
});
describe("init method", () => {
test("default options returned with no arguments provided", async () => {
const options = await init();
expect(options).toEqual({
"no-duplicate-heading": true,
"ol-prefix": "ordered",
"no-space-in-links": false,
"single-h1": true,
"no-emphasis-as-heading": true,
"no-empty-alt-text": false,
"heading-increment": true,
"no-generic-link-text": true,
"ul-style": {
style: "asterisk",
},
default: true,
"no-inline-html": false,
"no-bare-urls": false,
"no-blanks-blockquote": false,
"fenced-code-language": true,
"no-default-alt-text": true,
"no-alt-text": true,
});
});
test("arguments override default configuration", async () => {
const defaultOptions = await init();
const toTestOptions = Object.keys(defaultOptions).slice(0, 3);
// create a consumer config that is the opposite of the default config
const originalConfig = {};
const consumerConfig = {};
for (const key of toTestOptions) {
consumerConfig[key] = !defaultOptions[key];
originalConfig[key] = defaultOptions[key];
}
// confirm they are not the same
expect(originalConfig).not.toEqual(consumerConfig);
// do config step
const options = await init(consumerConfig);
// confirm config is set by consumer
expect(options).toHaveProperty(
toTestOptions[0],
consumerConfig[toTestOptions[0]],
);
expect(options).toHaveProperty(
toTestOptions[1],
consumerConfig[toTestOptions[1]],
);
expect(options).toHaveProperty(
toTestOptions[2],
consumerConfig[toTestOptions[2]],
);
});
});
});