markdownlint-rule-relative-.../test/basic.test.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

const test = require("node:test")
const assert = require("node:assert/strict")
const { markdownlint } = require("markdownlint").promises
2023-01-02 15:23:16 +01:00
const relativeLinks = require("../src/index.js")
2023-01-02 15:23:16 +01:00
test("ensure the rule validate correctly", async () => {
2023-01-02 15:23:16 +01:00
const lintResults = await markdownlint({
files: ["test/fixtures/Valid.md", "test/fixtures/Invalid.md"],
2023-01-02 15:23:16 +01:00
config: {
default: false,
"relative-links": true,
2023-01-02 15:23:16 +01:00
},
customRules: [relativeLinks],
2023-01-02 15:23:16 +01:00
})
assert.equal(lintResults["test/fixtures/Valid.md"].length, 0)
assert.equal(lintResults["test/fixtures/Invalid.md"].length, 3)
2023-01-02 19:45:46 +01:00
assert.equal(
lintResults["test/fixtures/Invalid.md"][0]?.ruleDescription,
"Relative links should be valid",
2023-01-02 15:23:16 +01:00
)
assert.equal(
lintResults["test/fixtures/Invalid.md"][0]?.errorDetail,
'Link "./basic.test.js" should exist in the file system',
2023-01-02 15:23:16 +01:00
)
2023-01-02 19:45:46 +01:00
assert.equal(
lintResults["test/fixtures/Invalid.md"][1]?.ruleDescription,
"Relative links should be valid",
2023-01-02 19:45:46 +01:00
)
assert.equal(
lintResults["test/fixtures/Invalid.md"][1]?.errorDetail,
'Link "../image.png" should exist in the file system',
)
assert.equal(
lintResults["test/fixtures/Invalid.md"][2]?.ruleDescription,
"Relative links should be valid",
)
assert.equal(
lintResults["test/fixtures/Invalid.md"][2]?.errorDetail,
'Link "./Valid.md#not-existing-heading" should have a valid fragment',
2023-01-02 19:45:46 +01:00
)
2023-01-02 15:23:16 +01:00
})