-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.test.js
38 lines (34 loc) · 1.04 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { expect, test } from 'vitest'
import { linkspector } from './linkspector.js'
let cmd = {
json: true,
}
test('linkspector should check top-level relative links in Markdown file', async () => {
let hasErrorLinks = false
let currentFile = '' // Variable to store the current file name
let results = [] // Array to store the results if json is true
for await (const { file, result } of linkspector(
'./.linkspector.test.yml',
cmd
)) {
currentFile = file
for (const linkStatusObj of result) {
if (cmd.json) {
results.push({
file: currentFile,
link: linkStatusObj.link,
status_code: linkStatusObj.status_code,
line_number: linkStatusObj.line_number,
position: linkStatusObj.position,
status: linkStatusObj.status,
error_message: linkStatusObj.error_message,
})
}
if (linkStatusObj.status === 'error') {
hasErrorLinks = true
}
}
}
expect(hasErrorLinks).toBe(false)
expect(results.length).toBe(21)
})