Skip to content

Commit ca281d1

Browse files
authored
Merge branch 'main' into meteorlxy-markdown-to-vue
2 parents 93b859a + 7dcdadc commit ca281d1

File tree

4 files changed

+91
-17
lines changed

4 files changed

+91
-17
lines changed

Diff for: e2e/docs/hmr/content.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## link to frontmatter
2+
3+
[frontmatter](./frontmatter.md)
4+
5+
## link to title
6+
7+
[title](./title.md)
8+
9+
## content
10+
11+
HMR content

Diff for: e2e/docs/hmr/frontmatter.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
foo: HMR foo
33
---
44

5+
## link to content
6+
7+
[content](./content.md)
8+
59
## link to title
610

711
[title](./title.md)

Diff for: e2e/docs/hmr/title.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# HMR Title
22

3+
## link to content
4+
5+
[content](./content.md)
6+
37
## link to frontmatter
48

59
[frontmatter](./frontmatter.md)

Diff for: e2e/tests/hmr.spec.ts

+72-17
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { expect, test } from '@playwright/test'
22
import { IS_DEV } from '../utils/env'
33
import { readSourceMarkdown, writeSourceMarkdown } from '../utils/source'
44

5-
const hmrUpdateTitle = async (): Promise<void> => {
6-
const markdownContent = await readSourceMarkdown('hmr/title.md')
5+
const hmrUpdateContent = async (): Promise<void> => {
6+
const markdownContent = await readSourceMarkdown('hmr/content.md')
77
await writeSourceMarkdown(
8-
'hmr/title.md',
9-
markdownContent.replace('# HMR Title', '# Updated Title'),
8+
'hmr/content.md',
9+
markdownContent.replace('HMR content', 'Updated content'),
1010
)
1111
}
1212

@@ -18,19 +18,32 @@ const hmrUpdateFrontmatter = async (): Promise<void> => {
1818
)
1919
}
2020

21+
const hmrUpdateTitle = async (): Promise<void> => {
22+
const markdownContent = await readSourceMarkdown('hmr/title.md')
23+
await writeSourceMarkdown(
24+
'hmr/title.md',
25+
markdownContent.replace('# HMR Title', '# Updated Title'),
26+
)
27+
}
28+
2129
const hmrRestore = async (): Promise<void> => {
22-
const titleMarkdownContent = await readSourceMarkdown('hmr/title.md')
30+
const contentMarkdownContent = await readSourceMarkdown('hmr/content.md')
2331
const frontmatterMarkdownContent =
2432
await readSourceMarkdown('hmr/frontmatter.md')
33+
const titleMarkdownContent = await readSourceMarkdown('hmr/title.md')
2534

2635
await writeSourceMarkdown(
27-
'hmr/title.md',
28-
titleMarkdownContent.replace('# Updated Title', '# HMR Title'),
36+
'hmr/content.md',
37+
contentMarkdownContent.replace('Updated content', 'HMR content'),
2938
)
3039
await writeSourceMarkdown(
3140
'hmr/frontmatter.md',
3241
frontmatterMarkdownContent.replace('foo: Updated foo', 'foo: HMR foo'),
3342
)
43+
await writeSourceMarkdown(
44+
'hmr/title.md',
45+
titleMarkdownContent.replace('# Updated Title', '# HMR Title'),
46+
)
3447
}
3548

3649
if (IS_DEV) {
@@ -41,6 +54,16 @@ if (IS_DEV) {
4154
await hmrRestore()
4255
})
4356

57+
test('should update content correctly', async ({ page }) => {
58+
const contentLocator = page.locator('.e2e-theme-content #content + p')
59+
60+
await page.goto('hmr/content.html')
61+
62+
await expect(contentLocator).toHaveText('HMR content')
63+
await hmrUpdateContent()
64+
await expect(contentLocator).toHaveText('Updated content')
65+
})
66+
4467
test('should update frontmatter correctly', async ({ page }) => {
4568
const frontmatterLocator = page.locator(
4669
'.e2e-theme-content #rendered-foo + p',
@@ -54,53 +77,85 @@ if (IS_DEV) {
5477
})
5578

5679
test('should update title correctly', async ({ page }) => {
57-
const titleLocator = page.locator('.e2e-theme-content #rendered-title + p')
80+
const titleLocator = page.locator('.e2e-theme-content h1')
81+
const renderedTitleLocator = page.locator(
82+
'.e2e-theme-content #rendered-title + p',
83+
)
5884

5985
await page.goto('hmr/title.html')
6086

6187
await expect(page).toHaveTitle(/HMR Title/)
6288
await expect(titleLocator).toHaveText('HMR Title')
89+
await expect(renderedTitleLocator).toHaveText('HMR Title')
6390
await hmrUpdateTitle()
6491
await expect(page).toHaveTitle(/Updated Title/)
6592
await expect(titleLocator).toHaveText('Updated Title')
93+
await expect(renderedTitleLocator).toHaveText('Updated Title')
6694
})
6795

68-
test('should update title and frontmatter correctly after navigation', async ({
96+
test('should update content and frontmatter and title correctly after navigation', async ({
6997
page,
7098
}) => {
71-
const titleLocator = page.locator('.e2e-theme-content #rendered-title + p')
99+
// text locators
100+
const contentLocator = page.locator('.e2e-theme-content #content + p')
72101
const frontmatterLocator = page.locator(
73102
'.e2e-theme-content #rendered-foo + p',
74103
)
104+
const titleLocator = page.locator('.e2e-theme-content #rendered-title + p')
105+
const renderedTitleLocator = page.locator(
106+
'.e2e-theme-content #rendered-title + p',
107+
)
75108

109+
// link locators
110+
const contentPageLinkLocator = page.locator(
111+
'.e2e-theme-content #link-to-content + p > a',
112+
)
113+
const frontmatterPageLinkLocator = page.locator(
114+
'.e2e-theme-content #link-to-frontmatter + p > a',
115+
)
116+
const titlePageLinkLocator = page.locator(
117+
'.e2e-theme-content #link-to-title + p > a',
118+
)
119+
120+
// start from title page
76121
await page.goto('hmr/title.html')
77122
await expect(page).toHaveTitle(/HMR Title/)
78123
await expect(titleLocator).toHaveText('HMR Title')
124+
await expect(renderedTitleLocator).toHaveText('HMR Title')
79125

80126
// update title page
81127
await hmrUpdateTitle()
82128
await expect(page).toHaveTitle(/Updated Title/)
83129
await expect(titleLocator).toHaveText('Updated Title')
130+
await expect(renderedTitleLocator).toHaveText('Updated Title')
84131

85132
// navigate to frontmatter page
86-
await page
87-
.locator('.e2e-theme-content #link-to-frontmatter + p > a')
88-
.click()
133+
await frontmatterPageLinkLocator.click()
89134
await expect(frontmatterLocator).toHaveText('HMR foo')
90135

91136
// update frontmatter page
92137
await hmrUpdateFrontmatter()
93138
await expect(frontmatterLocator).toHaveText('Updated foo')
94139

140+
// navigate to content page
141+
await contentPageLinkLocator.click()
142+
await expect(contentLocator).toHaveText('HMR content')
143+
144+
// update content page
145+
await hmrUpdateContent()
146+
await expect(contentLocator).toHaveText('Updated content')
147+
95148
// navigate to back title page
96-
await page.locator('.e2e-theme-content #link-to-title + p > a').click()
149+
await titlePageLinkLocator.click()
97150
await expect(page).toHaveTitle(/Updated Title/)
98151
await expect(titleLocator).toHaveText('Updated Title')
99152

100153
// navigate to back frontmatter page
101-
await page
102-
.locator('.e2e-theme-content #link-to-frontmatter + p > a')
103-
.click()
154+
await frontmatterPageLinkLocator.click()
104155
await expect(frontmatterLocator).toHaveText('Updated foo')
156+
157+
// navigate to back content page
158+
await contentPageLinkLocator.click()
159+
await expect(contentLocator).toHaveText('Updated content')
105160
})
106161
}

0 commit comments

Comments
 (0)