-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown-parser.test.ts
More file actions
82 lines (71 loc) · 1.99 KB
/
Copy pathmarkdown-parser.test.ts
File metadata and controls
82 lines (71 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { describe, expect, it } from 'vitest';
import { getMdxSource, parseHeadingsFromMdx } from './markdown-parser';
describe('parseHeadingsFromMdx', () => {
it('parses headings and keeps duplicate ids unique', () => {
const mdx = `
## Redis 개요
### 성능 포인트
## Redis 개요
`;
const headings = parseHeadingsFromMdx(mdx);
expect(headings).toHaveLength(3);
expect(headings[0]).toEqual({
id: 'redis-개요',
text: 'Redis 개요',
level: 2,
});
expect(headings[1]).toEqual({
id: '성능-포인트',
text: '성능 포인트',
level: 3,
});
expect(headings[2]).toEqual({
id: 'redis-개요-1',
text: 'Redis 개요',
level: 2,
});
});
it('normalizes markdown-heavy headings and skips non-renderable cases', () => {
const mdx = `
### **🚀 성능 증명 (로컬 벤치마크)**
### [Redis](https://redis.io) \`Pipeline\`
### **🎯**
\`\`\`md
## code block heading
\`\`\`
### **🚀 성능 증명 (로컬 벤치마크)**
`;
const headings = parseHeadingsFromMdx(mdx);
expect(headings).toEqual([
{
id: '성능-증명-로컬-벤치마크',
text: '🚀 성능 증명 (로컬 벤치마크)',
level: 3,
},
{
id: 'redis-pipeline',
text: 'Redis Pipeline',
level: 3,
},
{
id: '성능-증명-로컬-벤치마크-1',
text: '🚀 성능 증명 (로컬 벤치마크)',
level: 3,
},
]);
});
it('returns an empty array for invalid content', () => {
expect(parseHeadingsFromMdx('')).toEqual([]);
});
});
describe('getMdxSource', () => {
it('returns markdown source for an existing slug', () => {
const source = getMdxSource('redis-deep-dive-02-core-data-types');
expect(typeof source).toBe('string');
expect(source).toContain('#');
});
it('returns null when source cannot be loaded', () => {
const source = getMdxSource('does-not-exist-post');
expect(source).toBeNull();
});
});