2024-01-09 23:20:17 +01:00
|
|
|
const { test } = require("node:test")
|
2023-10-23 23:11:41 +02:00
|
|
|
const assert = require("node:assert/strict")
|
2023-06-24 09:58:45 +02:00
|
|
|
|
2023-10-23 23:11:41 +02:00
|
|
|
const { markdownlint } = require("markdownlint").promises
|
2023-01-02 15:23:16 +01:00
|
|
|
|
2023-10-23 23:11:41 +02:00
|
|
|
const relativeLinks = require("../src/index.js")
|
2023-01-02 15:23:16 +01:00
|
|
|
|
2023-10-23 23:11:41 +02:00
|
|
|
test("ensure the rule validate correctly", async () => {
|
2023-01-02 15:23:16 +01:00
|
|
|
const lintResults = await markdownlint({
|
2023-10-23 23:11:41 +02:00
|
|
|
files: ["test/fixtures/Valid.md", "test/fixtures/Invalid.md"],
|
2023-01-02 15:23:16 +01:00
|
|
|
config: {
|
2023-06-24 11:42:09 +02:00
|
|
|
default: false,
|
2023-10-23 23:11:41 +02:00
|
|
|
"relative-links": true,
|
2023-01-02 15:23:16 +01:00
|
|
|
},
|
2023-10-23 23:11:41 +02:00
|
|
|
customRules: [relativeLinks],
|
2023-01-02 15:23:16 +01:00
|
|
|
})
|
2024-01-09 23:20:17 +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
|
|
|
|
2023-06-24 09:58:45 +02:00
|
|
|
assert.equal(
|
2024-01-09 23:20:17 +01:00
|
|
|
lintResults["test/fixtures/Invalid.md"]?.[0]?.ruleDescription,
|
2023-10-23 23:11:41 +02:00
|
|
|
"Relative links should be valid",
|
2023-01-02 15:23:16 +01:00
|
|
|
)
|
2023-06-24 09:58:45 +02:00
|
|
|
assert.equal(
|
2024-01-09 23:20:17 +01:00
|
|
|
lintResults["test/fixtures/Invalid.md"]?.[0]?.errorDetail,
|
|
|
|
'"./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
|
|
|
|
2023-06-24 09:58:45 +02:00
|
|
|
assert.equal(
|
2024-01-09 23:20:17 +01:00
|
|
|
lintResults["test/fixtures/Invalid.md"]?.[1]?.ruleDescription,
|
2023-10-23 23:11:41 +02:00
|
|
|
"Relative links should be valid",
|
2023-01-02 19:45:46 +01:00
|
|
|
)
|
2023-06-24 09:58:45 +02:00
|
|
|
assert.equal(
|
2024-01-09 23:20:17 +01:00
|
|
|
lintResults["test/fixtures/Invalid.md"]?.[1]?.errorDetail,
|
|
|
|
'"../image.png" should exist in the file system',
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert.equal(
|
2024-01-09 23:20:17 +01:00
|
|
|
lintResults["test/fixtures/Invalid.md"]?.[2]?.ruleDescription,
|
2023-10-23 23:11:41 +02:00
|
|
|
"Relative links should be valid",
|
2023-06-24 11:42:09 +02:00
|
|
|
)
|
|
|
|
assert.equal(
|
2024-01-09 23:20:17 +01:00
|
|
|
lintResults["test/fixtures/Invalid.md"]?.[2]?.errorDetail,
|
|
|
|
'"./Valid.md#not-existing-heading" should have a valid fragment identifier',
|
2023-01-02 19:45:46 +01:00
|
|
|
)
|
2023-01-02 15:23:16 +01:00
|
|
|
})
|