Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
techfg authored and vernak2539 committed May 3, 2024
1 parent 9f8069c commit 7289457
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("astroRehypeRelativeMarkdownLinks", () => {
.process(input);

const expected =
'<html><head></head><body><a href="/dir-test-custom-slug/">foo</a></body></html>';
'<html><head></head><body><a href="/dir-test-custom-slug">foo</a></body></html>';

assert.equal(actual, expected);
});
Expand All @@ -97,7 +97,7 @@ describe("astroRehypeRelativeMarkdownLinks", () => {
assert.equal(actual, expected);
});

test("should transform non-root collection index.md paths", async () => {
test("should transform collection child directory index.md paths", async () => {
const input = '<a href="./fixtures/dir-test/index.md">foo</a>';
const { value: actual } = await rehype()
.use(testSetupRehype)
Expand All @@ -110,6 +110,19 @@ describe("astroRehypeRelativeMarkdownLinks", () => {
assert.equal(actual, expected);
});

test("should transform collection grandchild directory index.md paths", async () => {
const input = '<a href="./fixtures/dir-test/dir-test-child/index.md">foo</a>';
const { value: actual } = await rehype()
.use(testSetupRehype)
.use(astroRehypeRelativeMarkdownLinks, { contentPath: "src" })
.process(input);

const expected =
'<html><head></head><body><a href="/fixtures/dir-test/dir-test-child">foo</a></body></html>';

assert.equal(actual, expected);
});

test("should transform encoded file paths that exist with capital letters", async () => {
const input = '<a href="./fixtures/test%20with%20SPACE.md">foo</a>';
const { value: actual } = await rehype()
Expand Down Expand Up @@ -472,7 +485,7 @@ describe("astroRehypeRelativeMarkdownLinks", () => {
assert.equal(actual, expected);
});

test("should transform subdir index.md when content path same as collection path", async () => {
test("should transform collection child directory index.md when content path same as collection path", async () => {
const input = '<a href="./fixtures/dir-test/index.md">foo</a>';
const { value: actual } = await rehype()
.use(testSetupRehype)
Expand All @@ -488,6 +501,22 @@ describe("astroRehypeRelativeMarkdownLinks", () => {
assert.equal(actual, expected);
});

test("should transform collection grandchild directory index.md when content path same as collection path", async () => {
const input = '<a href="./fixtures/dir-test/dir-test-child/index.md">foo</a>';
const { value: actual } = await rehype()
.use(testSetupRehype)
.use(astroRehypeRelativeMarkdownLinks, {
contentPath: "src/fixtures",
collectionPathMode: "root",
})
.process(input);

const expected =
'<html><head></head><body><a href="/dir-test/dir-test-child">foo</a></body></html>';

assert.equal(actual, expected);
});

test("should transform subdir path when content path same as collection path", async () => {
const input = '<a href="./fixtures/dir-test/dir-test-child.md">foo</a>';
const { value: actual } = await rehype()
Expand Down

0 comments on commit 7289457

Please sign in to comment.