Skip to content

Commit

Permalink
test: fix & add tests for vernak2539#16
Browse files Browse the repository at this point in the history
  • Loading branch information
techfg committed Apr 7, 2024
1 parent d1a8cf6 commit fc75e8d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/fixtures/dir-test-custom-slug-2/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
slug: myindex
---

# Test
5 changes: 5 additions & 0 deletions src/fixtures/dir-test-custom-slug/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
slug: ''
---

Test
1 change: 1 addition & 0 deletions src/fixtures/dir-test/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Test
43 changes: 41 additions & 2 deletions src/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,54 @@ test("astroRehypeRelativeMarkdownLinks", async (t) => {
assert.equal(actual, expected);
});

await t.test("should transform index.md paths", async () => {
await t.test("should transform and contain index for root collection index.md paths", async () => {
const input = '<a href="./fixtures/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">foo</a></body></html>';
'<html><head></head><body><a href="/fixtures/index">foo</a></body></html>';

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

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

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

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

await t.test("should transform root collection index.md paths with non-empty string custom slug", async () => {
const input = '<a href="./fixtures/dir-test-custom-slug-2/index.md">foo</a>';
const { value: actual } = await rehype()
.use(testSetupRehype)
.use(astroRehypeRelativeMarkdownLinks, { contentPath: "src/fixtures" })
.process(input);

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

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

await t.test("should transform non-root collection index.md paths", async () => {
const input = '<a href="./fixtures/dir-test/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">foo</a></body></html>';

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

0 comments on commit fc75e8d

Please sign in to comment.