-
-
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.
Merge pull request #39 from UmbrellaDocs/dev-0.3.3
Dev 0.3.3
- Loading branch information
Showing
14 changed files
with
4,517 additions
and
1,956 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
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,20 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
- run: npm ci | ||
- run: npm test |
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,80 @@ | ||
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(false); | ||
expect(results.length).toBe(1); | ||
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"); | ||
}); | ||
|
||
test("linkspector should check 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( | ||
"./test/fixtures/relative/.relativeTest.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(7); | ||
expect(results[0].status).toBe("alive"); | ||
expect(results[1].status).toBe("alive"); | ||
expect(results[2].status).toBe("alive"); | ||
expect(results[3].status).toBe("alive"); | ||
expect(results[4].status).toBe("alive"); | ||
expect(results[5].status).toBe("alive"); | ||
expect(results[6].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
Oops, something went wrong.