-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: separate cases, so it's easier to know what fails
- Loading branch information
1 parent
1ddcdc7
commit 7465ffd
Showing
17 changed files
with
164 additions
and
88 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
# Invalid | ||
|
||
[File](./index.test.js) |
3 changes: 3 additions & 0 deletions
3
test/fixtures/invalid/non-existing-heading-fragment/awesome.md
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,3 @@ | ||
# Valid | ||
|
||
## Existing Heading |
3 changes: 3 additions & 0 deletions
3
...fixtures/invalid/non-existing-heading-fragment/non-existing-heading-fragment.md
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,3 @@ | ||
# Invalid | ||
|
||
[Link fragment](./awesome.md#non-existing-heading) |
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,3 @@ | ||
# Invalid | ||
|
||
![Image](./image.png) |
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,3 @@ | ||
# Valid | ||
|
||
[File](../../index.test.js) |
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,13 @@ | ||
# Valid | ||
|
||
## Existing Heading | ||
|
||
### Repeated Heading | ||
|
||
Text | ||
|
||
### Repeated Heading | ||
|
||
Text | ||
|
||
### Repeated Heading |
9 changes: 9 additions & 0 deletions
9
test/fixtures/valid/existing-heading-fragment/existing-heading-fragment.md
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,9 @@ | ||
# Valid | ||
|
||
[Link fragment](./awesome.md#existing-heading) | ||
|
||
[Link fragment Repeated 0](./awesome.md#repeated-heading) | ||
|
||
[Link fragment Repeated 1](./awesome.md#repeated-heading-1) | ||
|
||
[Link fragment Repeated 2](./awesome.md#repeated-heading-2) |
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,3 @@ | ||
# Valid | ||
|
||
![Image](./image.png) |
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,3 @@ | ||
# Valid | ||
|
||
![Absolute Path](/absolute/path.png) |
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 @@ | ||
# Valid | ||
|
||
[External https link](https://example.com/) | ||
|
||
[External https link 2](https:./external.https) | ||
|
||
[External ftp link](ftp:./external.ftp) |
File renamed without changes
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,112 @@ | ||
const { test } = require("node:test") | ||
const assert = require("node:assert/strict") | ||
|
||
const { markdownlint } = require("markdownlint").promises | ||
|
||
const relativeLinksRule = require("../src/index.js") | ||
|
||
/** | ||
* | ||
* @param {string} fixtureFile | ||
* @returns | ||
*/ | ||
const validateMarkdownLint = async (fixtureFile) => { | ||
const lintResults = await markdownlint({ | ||
files: [fixtureFile], | ||
config: { | ||
default: false, | ||
"relative-links": true, | ||
}, | ||
customRules: [relativeLinksRule], | ||
}) | ||
return lintResults[fixtureFile] | ||
} | ||
|
||
test("ensure the rule validates correctly", async (t) => { | ||
await t.test("should be valid", async (t) => { | ||
await t.test("with an existing heading fragment", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/valid/existing-heading-fragment/existing-heading-fragment.md", | ||
) | ||
assert.equal(lintResults?.length, 0) | ||
}) | ||
|
||
await t.test("with an existing file", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/valid/existing-file.md", | ||
) | ||
assert.equal(lintResults?.length, 0) | ||
}) | ||
|
||
await t.test("with an existing image", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/valid/existing-image.md", | ||
) | ||
assert.equal(lintResults?.length, 0) | ||
}) | ||
|
||
await t.test("should ignore absolute paths", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/valid/ignore-absolute-paths.md", | ||
) | ||
assert.equal(lintResults?.length, 0) | ||
}) | ||
|
||
await t.test("should ignore external links", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/valid/ignore-external-links.md", | ||
) | ||
assert.equal(lintResults?.length, 0) | ||
}) | ||
}) | ||
|
||
await t.test("should be invalid", async (t) => { | ||
await t.test("with a non-existing heading fragment", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/invalid/non-existing-heading-fragment/non-existing-heading-fragment.md", | ||
) | ||
assert.equal(lintResults?.length, 1) | ||
assert.deepEqual(lintResults?.[0]?.ruleNames, relativeLinksRule.names) | ||
assert.equal( | ||
lintResults?.[0]?.ruleDescription, | ||
relativeLinksRule.description, | ||
) | ||
assert.equal( | ||
lintResults?.[0]?.errorDetail, | ||
'"./awesome.md#non-existing-heading" should have a valid fragment identifier', | ||
) | ||
}) | ||
|
||
await t.test("with a non-existing file", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/invalid/non-existing-file.md", | ||
) | ||
assert.equal(lintResults?.length, 1) | ||
assert.deepEqual(lintResults?.[0]?.ruleNames, relativeLinksRule.names) | ||
assert.equal( | ||
lintResults?.[0]?.ruleDescription, | ||
relativeLinksRule.description, | ||
) | ||
assert.equal( | ||
lintResults?.[0]?.errorDetail, | ||
'"./index.test.js" should exist in the file system', | ||
) | ||
}) | ||
|
||
await t.test("with a non-existing image", async () => { | ||
const lintResults = await validateMarkdownLint( | ||
"test/fixtures/invalid/non-existing-image.md", | ||
) | ||
assert.equal(lintResults?.length, 1) | ||
assert.deepEqual(lintResults?.[0]?.ruleNames, relativeLinksRule.names) | ||
assert.equal( | ||
lintResults?.[0]?.ruleDescription, | ||
relativeLinksRule.description, | ||
) | ||
assert.equal( | ||
lintResults?.[0]?.errorDetail, | ||
'"./image.png" should exist in the file system', | ||
) | ||
}) | ||
}) | ||
}) |