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

37 lines
1.0 KiB
JavaScript
Raw Normal View History

const test = require('node:test')
const assert = require('node:assert/strict')
2023-01-02 15:23:16 +01:00
const { markdownlint } = require('markdownlint').promises
const relativeLinks = require('../src/index.js')
test('ensure we validate correctly', async () => {
2023-01-02 15:23:16 +01:00
const lintResults = await markdownlint({
files: ['test/fixtures/Valid.md', 'test/fixtures/Invalid.md'],
config: {
'relative-links': true
},
customRules: [relativeLinks]
})
assert.equal(lintResults['test/fixtures/Valid.md'].length, 0)
assert.equal(lintResults['test/fixtures/Invalid.md'].length, 2)
2023-01-02 19:45:46 +01:00
assert.equal(
2023-01-02 19:45:46 +01:00
lintResults['test/fixtures/Invalid.md'][0]?.ruleDescription,
2023-01-02 15:23:16 +01:00
'Relative links should be valid'
)
assert.equal(
2023-01-02 19:45:46 +01:00
lintResults['test/fixtures/Invalid.md'][0]?.errorDetail,
2023-01-02 15:23:16 +01:00
'Link "./basic.test.js" is dead'
)
2023-01-02 19:45:46 +01:00
assert.equal(
2023-01-02 19:45:46 +01:00
lintResults['test/fixtures/Invalid.md'][1]?.ruleDescription,
'Relative links should be valid'
)
assert.equal(
2023-01-02 19:45:46 +01:00
lintResults['test/fixtures/Invalid.md'][1]?.errorDetail,
'Link "../image.png" is dead'
)
2023-01-02 15:23:16 +01:00
})