Skip to content

Commit e597cab

Browse files
committed
test: fix unit tests
1 parent 5f156ae commit e597cab

File tree

5 files changed

+144
-173
lines changed

5 files changed

+144
-173
lines changed

packages/core/src/app/prepare/prepareRoutes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const HMR_CODE = `
88
if (import.meta.webpackHot) {
99
import.meta.webpackHot.accept()
1010
__VUE_HMR_RUNTIME__.updateRoutes?.(${ROUTES_VAR_NAME})
11-
__VUE_HMR_RUNTIME__.updateRedirects?.(${REDIRECTS_VAR_NAME}})
11+
__VUE_HMR_RUNTIME__.updateRedirects?.(${REDIRECTS_VAR_NAME})
1212
}
1313
1414
if (import.meta.hot) {

packages/core/src/types/page.ts

Lines changed: 120 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -4,133 +4,131 @@ import type { PageBase, PageData, PageFrontmatter } from '@vuepress/shared'
44
/**
55
* Vuepress Page
66
*/
7-
export type Page<
7+
export interface Page<
88
ExtraPageData extends Record<string, unknown> = Record<string, unknown>,
99
ExtraPageFrontmatter extends Record<string, unknown> = Record<
1010
string,
1111
unknown
1212
>,
13-
ExtraPageFields extends Record<string, unknown> = Record<string, unknown>,
14-
> = ExtraPageFields &
15-
PageBase<ExtraPageFrontmatter> & {
16-
/**
17-
* Data of the page, which will be available in client code
18-
*/
19-
data: PageData<ExtraPageData, ExtraPageFrontmatter>
20-
21-
/**
22-
* Raw Content of the page
23-
*/
24-
content: string
25-
26-
/**
27-
* Rendered content of the page
28-
*/
29-
contentRendered: string
30-
31-
/**
32-
* Date of the page, in 'yyyy-MM-dd' format
33-
*
34-
* @example '2020-09-09'
35-
*/
36-
date: string
37-
38-
/**
39-
* Dependencies of the page
40-
*/
41-
deps: string[]
42-
43-
/**
44-
* Links of the page
45-
*/
46-
links: MarkdownLink[]
47-
48-
/**
49-
* Markdown env object of the page
50-
*/
51-
markdownEnv: Record<string, unknown>
52-
53-
/**
54-
* Path of the page that inferred from file path
55-
*
56-
* If the page does not come from a file, it would be `null`
57-
*
58-
* @example '/guide/index.html'
59-
*/
60-
pathInferred: string | null
61-
62-
/**
63-
* Locale path prefix of the page
64-
*
65-
* @example '/getting-started.html' -> '/'
66-
* @example '/en/getting-started.html' -> '/en/'
67-
* @example '/zh/getting-started.html' -> '/zh/'
68-
*/
69-
pathLocale: string
70-
71-
/**
72-
* Permalink of the page
73-
*
74-
* If the page does not have a permalink, it would be `null`
75-
*/
76-
permalink: string | null
77-
78-
/**
79-
* Custom data to be attached to route record
80-
*/
81-
routeMeta: Record<string, unknown>
82-
83-
/**
84-
* Extracted sfc blocks of the page
85-
*/
86-
sfcBlocks: MarkdownSfcBlocks
87-
88-
/**
89-
* Slug of the page
90-
*/
91-
slug: string
92-
93-
/**
94-
* Source file path
95-
*
96-
* If the page does not come from a file, it would be `null`
97-
*/
98-
filePath: string | null
99-
100-
/**
101-
* Source file path relative to source directory
102-
*
103-
* If the page does not come from a file, it would be `null`
104-
*/
105-
filePathRelative: string | null
106-
107-
/**
108-
* Chunk file path
109-
*/
110-
chunkFilePath: string
111-
112-
/**
113-
* Chunk file path relative to temp directory
114-
*/
115-
chunkFilePathRelative: string
116-
117-
/**
118-
* Chunk name
119-
*
120-
* This will only take effect in webpack
121-
*/
122-
chunkName: string
123-
124-
/**
125-
* Rendered html file path
126-
*/
127-
htmlFilePath: string
128-
129-
/**
130-
* Rendered html file path relative to dest directory
131-
*/
132-
htmlFilePathRelative: string
133-
}
13+
> extends PageBase<ExtraPageFrontmatter> {
14+
/**
15+
* Data of the page, which will be available in client code
16+
*/
17+
data: PageData<ExtraPageData, ExtraPageFrontmatter>
18+
19+
/**
20+
* Raw Content of the page
21+
*/
22+
content: string
23+
24+
/**
25+
* Rendered content of the page
26+
*/
27+
contentRendered: string
28+
29+
/**
30+
* Date of the page, in 'yyyy-MM-dd' format
31+
*
32+
* @example '2020-09-09'
33+
*/
34+
date: string
35+
36+
/**
37+
* Dependencies of the page
38+
*/
39+
deps: string[]
40+
41+
/**
42+
* Links of the page
43+
*/
44+
links: MarkdownLink[]
45+
46+
/**
47+
* Markdown env object of the page
48+
*/
49+
markdownEnv: Record<string, unknown>
50+
51+
/**
52+
* Path of the page that inferred from file path
53+
*
54+
* If the page does not come from a file, it would be `null`
55+
*
56+
* @example '/guide/index.html'
57+
*/
58+
pathInferred: string | null
59+
60+
/**
61+
* Locale path prefix of the page
62+
*
63+
* @example '/getting-started.html' -> '/'
64+
* @example '/en/getting-started.html' -> '/en/'
65+
* @example '/zh/getting-started.html' -> '/zh/'
66+
*/
67+
pathLocale: string
68+
69+
/**
70+
* Permalink of the page
71+
*
72+
* If the page does not have a permalink, it would be `null`
73+
*/
74+
permalink: string | null
75+
76+
/**
77+
* Custom data to be attached to route record
78+
*/
79+
routeMeta: Record<string, unknown>
80+
81+
/**
82+
* Extracted sfc blocks of the page
83+
*/
84+
sfcBlocks: MarkdownSfcBlocks
85+
86+
/**
87+
* Slug of the page
88+
*/
89+
slug: string
90+
91+
/**
92+
* Source file path
93+
*
94+
* If the page does not come from a file, it would be `null`
95+
*/
96+
filePath: string | null
97+
98+
/**
99+
* Source file path relative to source directory
100+
*
101+
* If the page does not come from a file, it would be `null`
102+
*/
103+
filePathRelative: string | null
104+
105+
/**
106+
* Chunk file path
107+
*/
108+
chunkFilePath: string
109+
110+
/**
111+
* Chunk file path relative to temp directory
112+
*/
113+
chunkFilePathRelative: string
114+
115+
/**
116+
* Chunk name
117+
*
118+
* This will only take effect in webpack
119+
*/
120+
chunkName: string
121+
122+
/**
123+
* Rendered html file path
124+
*/
125+
htmlFilePath: string
126+
127+
/**
128+
* Rendered html file path relative to dest directory
129+
*/
130+
htmlFilePathRelative: string
131+
}
134132

135133
/**
136134
* Options to create vuepress page

packages/core/tests/page/createPage.spec.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,13 @@ describe('should work without plugins', () => {
7373
expect(page.filePathRelative).toBeNull()
7474
expect(page.htmlFilePath).toBe(app.dir.dest(`index.html`))
7575
expect(page.htmlFilePathRelative).toBe(`index.html`)
76-
expect(page.componentFilePath).toBe(
77-
app.dir.temp(`pages/${page.htmlFilePathRelative}.vue`),
78-
)
79-
expect(page.componentFilePathRelative).toBe(
80-
`pages/${page.htmlFilePathRelative}.vue`,
81-
)
8276
expect(page.chunkFilePath).toBe(
83-
app.dir.temp(`pages/${page.htmlFilePathRelative}.js`),
77+
app.dir.temp(`pages/${page.htmlFilePathRelative}.vue`),
8478
)
8579
expect(page.chunkFilePathRelative).toBe(
86-
`pages/${page.htmlFilePathRelative}.js`,
80+
`pages/${page.htmlFilePathRelative}.vue`,
8781
)
88-
expect(page.chunkName).toBeTruthy()
82+
expect(page.chunkName).toBe(`index.html`)
8983
})
9084
})
9185

packages/core/tests/page/resolvePageChunkInfo.spec.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@ const app = createBaseApp({
99
bundler: {} as Bundler,
1010
})
1111

12-
it('should resolve page chunk info correctly', () => {
12+
it('should resolve page chunk info correctly without source file path', () => {
1313
const resolved = resolvePageChunkInfo({
1414
app,
15+
filePath: null,
16+
filePathRelative: null,
1517
htmlFilePathRelative: 'foo.html',
1618
})
1719

1820
expect(resolved).toEqual({
19-
chunkFilePath: app.dir.temp('pages/foo.html.js'),
20-
chunkFilePathRelative: 'pages/foo.html.js',
21+
chunkFilePath: app.dir.temp('pages/foo.html.vue'),
22+
chunkFilePathRelative: 'pages/foo.html.vue',
23+
chunkName: sanitizeFileName('foo.html'),
24+
})
25+
})
26+
27+
it('should resolve page chunk info correctly with source file path', () => {
28+
const resolved = resolvePageChunkInfo({
29+
app,
30+
filePath: app.dir.source('foo.md'),
31+
filePathRelative: 'foo.md',
32+
htmlFilePathRelative: 'foo.html',
33+
})
34+
35+
expect(resolved).toEqual({
36+
chunkFilePath: app.dir.source('foo.md'),
37+
chunkFilePathRelative: 'foo.md',
2138
chunkName: sanitizeFileName('foo.html'),
2239
})
2340
})

packages/core/tests/page/resolvePageComponentInfo.spec.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)