-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix): getReferencedMarkdownFiles should ignore http/https links (#3169)
- Loading branch information
1 parent
2a09428
commit f53b56e
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/cli/yaml/docs-validator/src/__test__/valid-markdown-link.test.ts
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,49 @@ | ||
import { AbsoluteFilePath } from "@fern-api/fs-utils"; | ||
import { getReferencedMarkdownFiles } from "../rules/valid-markdown-link/valid-markdown-link"; | ||
|
||
describe("getReferencedMarkdownFiles", () => { | ||
it("should match on .md and .mdx", () => { | ||
const content = ` | ||
[Link to a markdown file](./file1.md) | ||
[Link to an mdx file](./file2.mdx) | ||
`; | ||
|
||
const links = getReferencedMarkdownFiles({ | ||
content, | ||
absoluteFilepath: AbsoluteFilePath.of("/path/to/fern/file0.md") | ||
}); | ||
|
||
expect(links).toEqual([ | ||
{ path: "./file1.md", absolutePath: AbsoluteFilePath.of("/path/to/fern/file1.md") }, | ||
{ path: "./file2.mdx", absolutePath: AbsoluteFilePath.of("/path/to/fern/file2.mdx") } | ||
]); | ||
}); | ||
|
||
it("should not match on non-markdown files", () => { | ||
const content = ` | ||
[Link to a non-markdown file](./file1.txt) | ||
[Link to a non-markdown file](./file2.js) | ||
`; | ||
|
||
const links = getReferencedMarkdownFiles({ | ||
content, | ||
absoluteFilepath: AbsoluteFilePath.of("/path/to/fern/file0.md") | ||
}); | ||
|
||
expect(links).toEqual([]); | ||
}); | ||
|
||
it("should not match on http or https links", () => { | ||
const content = ` | ||
[Link to a http file](http://example.com/file1.md) | ||
[Link to a https file](https://example.com/file2.md) | ||
`; | ||
|
||
const links = getReferencedMarkdownFiles({ | ||
content, | ||
absoluteFilepath: AbsoluteFilePath.of("/path/to/fern/file0.md") | ||
}); | ||
|
||
expect(links).toEqual([]); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/cli/yaml/docs-validator/src/rules/valid-markdown-link/valid-markdown-link.ts
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