Skip to content

Commit 9cf0d21

Browse files
committed
test(core): add unit tests for page
1 parent acad7a3 commit 9cf0d21

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

packages/@vuepress/core/__tests__/page/resolvePageHtmlInfo.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const testCases: [string, string][] = [
1717

1818
describe('core > page > resolvePageHtmlInfo', () => {
1919
describe('should resolve page html file path correctly', () => {
20-
testCases.forEach(([pagePath, htmlFilePathRelative]) => {
20+
testCases.forEach(([source, expected]) => {
2121
it(JSON.stringify(source), () => {
2222
expect(
2323
resolvePageHtmlInfo({
2424
app,
25-
path: pagePath,
25+
path: source,
2626
})
2727
).toEqual({
28-
htmlFilePath: app.dir.dest(htmlFilePathRelative),
29-
htmlFilePathRelative,
28+
htmlFilePath: app.dir.dest(expected),
29+
htmlFilePathRelative: expected,
3030
})
3131
})
3232
})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { createApp, resolvePageLang } from '@vuepress/core'
2+
import { path } from '@vuepress/utils'
3+
4+
const source = path.resolve(__dirname, 'fake-source')
5+
const app = createApp({
6+
source,
7+
lang: 'site-lang',
8+
locales: {
9+
'/': {
10+
lang: 'locales-lang',
11+
},
12+
},
13+
})
14+
15+
describe('core > page > resolvePageLang', () => {
16+
it('should use frontmatter lang', () => {
17+
const lang = resolvePageLang({
18+
app,
19+
frontmatter: {
20+
lang: 'frontmatter-lang',
21+
},
22+
pathLocale: '/',
23+
})
24+
25+
expect(lang).toBe('frontmatter-lang')
26+
})
27+
28+
it('should use locales lang 1', () => {
29+
const lang = resolvePageLang({
30+
app,
31+
frontmatter: {
32+
lang: '',
33+
},
34+
pathLocale: '/',
35+
})
36+
37+
expect(lang).toBe('locales-lang')
38+
})
39+
40+
it('should use locales lang 2', () => {
41+
const lang = resolvePageLang({
42+
app,
43+
frontmatter: {},
44+
pathLocale: '/',
45+
})
46+
47+
expect(lang).toBe('locales-lang')
48+
})
49+
50+
it('should use site lang', () => {
51+
const lang = resolvePageLang({
52+
app,
53+
frontmatter: {},
54+
pathLocale: '/foo/',
55+
})
56+
57+
expect(lang).toBe('site-lang')
58+
})
59+
})

0 commit comments

Comments
 (0)