Skip to content

Commit 698806f

Browse files
committed
test: extract headers
1 parent d8686a0 commit 698806f

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ describe('markdown page', () => {
121121

122122
expect(page.excerpt).toMatchSnapshot()
123123
})
124+
125+
test('should extract level 2 and 3 headers by default', async () => {
126+
const { relative, filePath } = getDocument('alpha.md')
127+
const markdown = getMarkdown()
128+
const page = await setupPage({ filePath, relative }, { markdown })
129+
130+
expect(page.headers).toMatchSnapshot()
131+
})
132+
133+
test('should extract headers by config', async () => {
134+
const { relative, filePath } = getDocument('alpha.md')
135+
const markdown = getMarkdown()
136+
const extractHeaders = ['h1', 'h2']
137+
const page = await setupPage({ filePath, relative, extractHeaders }, { markdown })
138+
139+
expect(page.headers).toMatchSnapshot()
140+
})
124141
})
125142

126143
describe('title', () => {
@@ -259,5 +276,4 @@ describe('public api', () => {
259276
// TODO I18n
260277
// TODO Add a page with explicit content
261278
// TODO SFC
262-
// TODO Headers
263279

packages/@vuepress/core/lib/node/__tests__/prepare/__snapshots__/Page.spec.js.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,33 @@ exports[`markdown page should extract any content above <!-- more --> as excerpt
44
<h1 id="excerpt"><a class="header-anchor" href="#excerpt" aria-hidden="true">#</a> Excerpt</h1>
55
<p>Blablabla...</p>
66
`;
7+
8+
exports[`markdown page should extract headers by config 1`] = `
9+
Array [
10+
Object {
11+
"level": 1,
12+
"slug": "alpha",
13+
"title": "Alpha",
14+
},
15+
Object {
16+
"level": 2,
17+
"slug": "h2",
18+
"title": "h2",
19+
},
20+
]
21+
`;
22+
23+
exports[`markdown page should extract level 2 and 3 headers by default 1`] = `
24+
Array [
25+
Object {
26+
"level": 2,
27+
"slug": "h2",
28+
"title": "h2",
29+
},
30+
Object {
31+
"level": 3,
32+
"slug": "h3",
33+
"title": "h3",
34+
},
35+
]
36+
`;

packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs/alpha.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ title: VuePress Alpha
33
---
44

55
# Alpha
6+
7+
## h2
8+
9+
### h3

0 commit comments

Comments
 (0)