Skip to content

Commit 22c02f3

Browse files
committed
Add test for replacing reference links within a doc
1 parent 3976dd5 commit 22c02f3

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
id: doc3
3+
title: Document 3
4+
---
5+
6+
### Existing Docs
7+
8+
- [doc1][doc1]
9+
- [doc2][doc2]
10+
11+
### Non-existing Docs
12+
13+
- [hahaha][hahaha]
14+
15+
## Repeating Docs
16+
17+
- [doc1][doc1]
18+
- [doc2][doc2]
19+
20+
## Do not replace this
21+
```md
22+
![image1][image1]
23+
```
24+
25+
```js
26+
const doc1 = foo();
27+
console.log("[image2][image2]");
28+
const testStr = `![image3][image3]`;
29+
```
30+
31+
[doc1]: doc1.md
32+
[doc2]: ./doc2.md
33+
[hahaha]: hahaha.md
34+
[image1]: assets/image1.png
35+
[image2]: assets/image2.jpg
36+
[image3]: assets/image3.gif

v1/lib/server/__tests__/docs.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ const doc2 = fs.readFileSync(
5050
'utf8',
5151
);
5252

53+
const doc3 = fs.readFileSync(
54+
path.join(__dirname, '__fixtures__', 'doc3.md'),
55+
'utf8',
56+
);
57+
5358
const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
5459
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
60+
const rawContent3 = metadataUtils.extractMetadata(doc3).rawContent;
5561

5662
describe('mdToHtmlify', () => {
5763
const mdToHtml = metadataUtils.mdToHtml(Metadata, '/');
@@ -77,6 +83,17 @@ describe('mdToHtmlify', () => {
7783
expect(content2).toMatchSnapshot();
7884
expect(content2).not.toEqual(rawContent2);
7985
});
86+
87+
test('transforms reference links', () => {
88+
const content3 = docs.mdToHtmlify(
89+
rawContent3,
90+
mdToHtml,
91+
Metadata['en-doc3'],
92+
);
93+
expect(content3).toContain('/docs/en/next/');
94+
expect(content3).toMatchSnapshot();
95+
expect(content3).not.toEqual(rawContent3);
96+
})
8097
});
8198

8299
describe('getFile', () => {

0 commit comments

Comments
 (0)