Skip to content

Commit 524625f

Browse files
committed
test: reorganize hmr e2e tests and add retries config
1 parent a7a23f7 commit 524625f

File tree

6 files changed

+140
-184
lines changed

6 files changed

+140
-184
lines changed

e2e/cypress.config.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,61 @@ export default defineConfig({
1414
'hmr:title': async () => {
1515
const hmrTitleSourceMarkdownPath =
1616
resolveSourceMarkdownPath('hmr/title.md')
17-
const content = await fs.readFile(hmrTitleSourceMarkdownPath, 'utf-8')
18-
await fs.writeFile(
17+
const hmrTitleSourceMarkdownContent = await fs.readFile(
1918
hmrTitleSourceMarkdownPath,
20-
content.replace('# HMR Title', '# Updated Title'),
19+
'utf-8',
2120
)
22-
return true
23-
},
24-
'hmr:title:restore': async () => {
25-
const hmrTitleSourceMarkdownPath =
26-
resolveSourceMarkdownPath('hmr/title.md')
27-
const content = await fs.readFile(hmrTitleSourceMarkdownPath, 'utf-8')
2821
await fs.writeFile(
2922
hmrTitleSourceMarkdownPath,
30-
content.replace('# Updated Title', '# HMR Title'),
23+
hmrTitleSourceMarkdownContent.replace(
24+
'# HMR Title',
25+
'# Updated Title',
26+
),
3127
)
3228
return true
3329
},
3430
'hmr:frontmatter': async () => {
3531
const hmrFrontmatterSourceMarkdownPath =
3632
resolveSourceMarkdownPath('hmr/frontmatter.md')
37-
const content = await fs.readFile(
33+
const hmrFrontmatterSourceMarkdownContent = await fs.readFile(
3834
hmrFrontmatterSourceMarkdownPath,
3935
'utf-8',
4036
)
4137
await fs.writeFile(
4238
hmrFrontmatterSourceMarkdownPath,
43-
content.replace('foo: HMR foo', 'foo: Updated foo'),
39+
hmrFrontmatterSourceMarkdownContent.replace(
40+
'foo: HMR foo',
41+
'foo: Updated foo',
42+
),
4443
)
4544
return true
4645
},
47-
'hmr:frontmatter:restore': async () => {
46+
'hmr:restore': async () => {
47+
const hmrTitleSourceMarkdownPath =
48+
resolveSourceMarkdownPath('hmr/title.md')
49+
const hmrTitleSourceMarkdownContent = await fs.readFile(
50+
hmrTitleSourceMarkdownPath,
51+
'utf-8',
52+
)
53+
await fs.writeFile(
54+
hmrTitleSourceMarkdownPath,
55+
hmrTitleSourceMarkdownContent.replace(
56+
'# Updated Title',
57+
'# HMR Title',
58+
),
59+
)
4860
const hmrFrontmatterSourceMarkdownPath =
4961
resolveSourceMarkdownPath('hmr/frontmatter.md')
50-
const content = await fs.readFile(
62+
const hmrFrontmatterSourceMarkdownContent = await fs.readFile(
5163
hmrFrontmatterSourceMarkdownPath,
5264
'utf-8',
5365
)
5466
await fs.writeFile(
5567
hmrFrontmatterSourceMarkdownPath,
56-
content.replace('foo: Updated foo', 'foo: HMR foo'),
68+
hmrFrontmatterSourceMarkdownContent.replace(
69+
'foo: Updated foo',
70+
'foo: HMR foo',
71+
),
5772
)
5873
return true
5974
},

e2e/tests/hmr.cy.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
if (Cypress.env('E2E_COMMAND') === 'dev') {
2+
const retries = 5
3+
4+
beforeEach(() => cy.task('hmr:restore'))
5+
after(() => cy.task('hmr:restore'))
6+
7+
it('should update frontmatter correctly', { retries }, () => {
8+
cy.visit('/hmr/frontmatter.html')
9+
cy.get('.e2e-theme-content #rendered-foo + p').should(
10+
'have.text',
11+
'HMR foo',
12+
)
13+
14+
cy.task('hmr:frontmatter').then(() => {
15+
cy.get('.e2e-theme-content #rendered-foo + p').should(
16+
'have.text',
17+
'Updated foo',
18+
)
19+
})
20+
})
21+
22+
it('should update title correctly', { retries }, () => {
23+
cy.visit('/hmr/title.html')
24+
cy.title().should('include', 'HMR Title')
25+
cy.get('.e2e-theme-content #rendered-title + p').should(
26+
'have.text',
27+
'HMR Title',
28+
)
29+
30+
cy.task('hmr:title').then(() => {
31+
cy.title().should('include', 'Updated Title')
32+
cy.get('.e2e-theme-content #rendered-title + p').should(
33+
'have.text',
34+
'Updated Title',
35+
)
36+
})
37+
})
38+
39+
it(
40+
'should update title and frontmatter correctly after navigation',
41+
{ retries },
42+
() => {
43+
cy.visit('/hmr/title.html')
44+
cy.title().should('include', 'HMR Title')
45+
cy.get('.e2e-theme-content #rendered-title + p').should(
46+
'have.text',
47+
'HMR Title',
48+
)
49+
50+
// update title page
51+
cy.task('hmr:title')
52+
.then(() => {
53+
cy.title().should('include', 'Updated Title')
54+
cy.get('.e2e-theme-content #rendered-title + p').should(
55+
'have.text',
56+
'Updated Title',
57+
)
58+
})
59+
// navigate to frontmatter page
60+
.then(() => {
61+
cy.get('.e2e-theme-content #link-to-frontmatter + p > a').click()
62+
cy.get('.e2e-theme-content #rendered-foo + p').should(
63+
'have.text',
64+
'HMR foo',
65+
)
66+
})
67+
// update frontmatter page
68+
.then(() => cy.task('hmr:frontmatter'))
69+
.then(() => {
70+
cy.get('.e2e-theme-content #rendered-foo + p').should(
71+
'have.text',
72+
'Updated foo',
73+
)
74+
})
75+
// navigate to title page
76+
.then(() => {
77+
cy.get('.e2e-theme-content #link-to-title + p > a').click()
78+
cy.get('.e2e-theme-content #rendered-title + p').should(
79+
'have.text',
80+
'Updated Title',
81+
)
82+
})
83+
// navigate to frontmatter page
84+
.then(() => {
85+
cy.get('.e2e-theme-content #link-to-frontmatter + p > a').click()
86+
cy.get('.e2e-theme-content #rendered-foo + p').should(
87+
'have.text',
88+
'Updated foo',
89+
)
90+
})
91+
},
92+
)
93+
}

e2e/tests/hmr/frontmatter.cy.ts

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

e2e/tests/hmr/navigation.cy.ts

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

e2e/tests/hmr/title.cy.ts

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

e2e/tests/markdown/anchors.cy.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
it(
2-
'should render anchors and navigate correctly',
3-
// this test is randomly failing on CI, so we need to retry it
4-
{ retries: 3 },
5-
() => {
6-
cy.visit('/markdown/anchors.html')
1+
const retries = 5
72

8-
cy.get('.e2e-theme-content h1')
9-
.should('have.attr', 'id', 'title')
10-
.should('have.attr', 'tabindex', '-1')
3+
it('should render anchors and navigate correctly', { retries }, () => {
4+
cy.visit('/markdown/anchors.html')
115

12-
cy.get('.e2e-theme-content h1 > a')
13-
.should('have.attr', 'class', 'header-anchor')
14-
.should('have.attr', 'href', '#title')
15-
.click()
6+
cy.get('.e2e-theme-content h1')
7+
.should('have.attr', 'id', 'title')
8+
.should('have.attr', 'tabindex', '-1')
169

17-
cy.hash().should('eq', '#title')
10+
cy.get('.e2e-theme-content h1 > a')
11+
.should('have.attr', 'class', 'header-anchor')
12+
.should('have.attr', 'href', '#title')
13+
.click()
1814

19-
cy.get('#anchor-1-1 > a')
20-
.should('have.attr', 'class', 'header-anchor')
21-
.click()
15+
cy.hash().should('eq', '#title')
2216

23-
cy.hash().should('eq', '#anchor-1-1')
24-
},
25-
)
17+
cy.get('#anchor-1-1 > a')
18+
.should('have.attr', 'class', 'header-anchor')
19+
.click()
20+
21+
cy.hash().should('eq', '#anchor-1-1')
22+
})

0 commit comments

Comments
 (0)