-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed image links check, added test for verifying image links
- Loading branch information
1 parent
8755aed
commit 84dc8a3
Showing
5 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expect, test } from "vitest"; | ||
import { linkspector } from "./linkspector.js"; | ||
|
||
let cmd = { | ||
json: true, | ||
}; | ||
|
||
test("linkspector should check image 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( | ||
"./test/fixtures/image/imageTest.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(true); | ||
expect(results.length).toBe(2); | ||
expect(results[0].link).toBe("https://commons.wikimedia.org/wiki/Main_Page#/media/File:Praia_do_Ribeiro_do_Cavalo2.jpg"); | ||
expect(results[0].status).toBe("alive"); | ||
expect(results[1].link).toBe("https://suygfuysgf6fe76afawe.com/image.jpg"); | ||
expect(results[1].status).toBe("error"); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Check image links | ||
|
||
Working link: | ||
![Praia_do_Ribeiro_do_Cavalo2](https://commons.wikimedia.org/wiki/Main_Page#/media/File:Praia_do_Ribeiro_do_Cavalo2.jpg) | ||
|
||
Broken link: | ||
![Broken Image](https://suygfuysgf6fe76afawe.com/image.jpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dirs: | ||
- ./test/fixtures/image |