Skip to content

Commit

Permalink
test: reorganize hmr e2e tests and add retries config
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Feb 19, 2024
1 parent a7a23f7 commit 524625f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 184 deletions.
45 changes: 30 additions & 15 deletions e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,61 @@ export default defineConfig({
'hmr:title': async () => {
const hmrTitleSourceMarkdownPath =
resolveSourceMarkdownPath('hmr/title.md')
const content = await fs.readFile(hmrTitleSourceMarkdownPath, 'utf-8')
await fs.writeFile(
const hmrTitleSourceMarkdownContent = await fs.readFile(
hmrTitleSourceMarkdownPath,
content.replace('# HMR Title', '# Updated Title'),
'utf-8',
)
return true
},
'hmr:title:restore': async () => {
const hmrTitleSourceMarkdownPath =
resolveSourceMarkdownPath('hmr/title.md')
const content = await fs.readFile(hmrTitleSourceMarkdownPath, 'utf-8')
await fs.writeFile(
hmrTitleSourceMarkdownPath,
content.replace('# Updated Title', '# HMR Title'),
hmrTitleSourceMarkdownContent.replace(
'# HMR Title',
'# Updated Title',
),
)
return true
},
'hmr:frontmatter': async () => {
const hmrFrontmatterSourceMarkdownPath =
resolveSourceMarkdownPath('hmr/frontmatter.md')
const content = await fs.readFile(
const hmrFrontmatterSourceMarkdownContent = await fs.readFile(
hmrFrontmatterSourceMarkdownPath,
'utf-8',
)
await fs.writeFile(
hmrFrontmatterSourceMarkdownPath,
content.replace('foo: HMR foo', 'foo: Updated foo'),
hmrFrontmatterSourceMarkdownContent.replace(
'foo: HMR foo',
'foo: Updated foo',
),
)
return true
},
'hmr:frontmatter:restore': async () => {
'hmr:restore': async () => {
const hmrTitleSourceMarkdownPath =
resolveSourceMarkdownPath('hmr/title.md')
const hmrTitleSourceMarkdownContent = await fs.readFile(
hmrTitleSourceMarkdownPath,
'utf-8',
)
await fs.writeFile(
hmrTitleSourceMarkdownPath,
hmrTitleSourceMarkdownContent.replace(
'# Updated Title',
'# HMR Title',
),
)
const hmrFrontmatterSourceMarkdownPath =
resolveSourceMarkdownPath('hmr/frontmatter.md')
const content = await fs.readFile(
const hmrFrontmatterSourceMarkdownContent = await fs.readFile(
hmrFrontmatterSourceMarkdownPath,
'utf-8',
)
await fs.writeFile(
hmrFrontmatterSourceMarkdownPath,
content.replace('foo: Updated foo', 'foo: HMR foo'),
hmrFrontmatterSourceMarkdownContent.replace(
'foo: Updated foo',
'foo: HMR foo',
),
)
return true
},
Expand Down
93 changes: 93 additions & 0 deletions e2e/tests/hmr.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
if (Cypress.env('E2E_COMMAND') === 'dev') {
const retries = 5

beforeEach(() => cy.task('hmr:restore'))
after(() => cy.task('hmr:restore'))

it('should update frontmatter correctly', { retries }, () => {
cy.visit('/hmr/frontmatter.html')
cy.get('.e2e-theme-content #rendered-foo + p').should(
'have.text',
'HMR foo',
)

cy.task('hmr:frontmatter').then(() => {
cy.get('.e2e-theme-content #rendered-foo + p').should(
'have.text',
'Updated foo',
)
})
})

it('should update title correctly', { retries }, () => {
cy.visit('/hmr/title.html')
cy.title().should('include', 'HMR Title')
cy.get('.e2e-theme-content #rendered-title + p').should(
'have.text',
'HMR Title',
)

cy.task('hmr:title').then(() => {
cy.title().should('include', 'Updated Title')
cy.get('.e2e-theme-content #rendered-title + p').should(
'have.text',
'Updated Title',
)
})
})

it(
'should update title and frontmatter correctly after navigation',
{ retries },
() => {
cy.visit('/hmr/title.html')
cy.title().should('include', 'HMR Title')
cy.get('.e2e-theme-content #rendered-title + p').should(
'have.text',
'HMR Title',
)

// update title page
cy.task('hmr:title')
.then(() => {
cy.title().should('include', 'Updated Title')
cy.get('.e2e-theme-content #rendered-title + p').should(
'have.text',
'Updated Title',
)
})
// navigate to frontmatter page
.then(() => {
cy.get('.e2e-theme-content #link-to-frontmatter + p > a').click()
cy.get('.e2e-theme-content #rendered-foo + p').should(
'have.text',
'HMR foo',
)
})
// update frontmatter page
.then(() => cy.task('hmr:frontmatter'))
.then(() => {
cy.get('.e2e-theme-content #rendered-foo + p').should(
'have.text',
'Updated foo',
)
})
// navigate to title page
.then(() => {
cy.get('.e2e-theme-content #link-to-title + p > a').click()
cy.get('.e2e-theme-content #rendered-title + p').should(
'have.text',
'Updated Title',
)
})
// navigate to frontmatter page
.then(() => {
cy.get('.e2e-theme-content #link-to-frontmatter + p > a').click()
cy.get('.e2e-theme-content #rendered-foo + p').should(
'have.text',
'Updated foo',
)
})
},
)
}
28 changes: 0 additions & 28 deletions e2e/tests/hmr/frontmatter.cy.ts

This file was deleted.

90 changes: 0 additions & 90 deletions e2e/tests/hmr/navigation.cy.ts

This file was deleted.

31 changes: 0 additions & 31 deletions e2e/tests/hmr/title.cy.ts

This file was deleted.

37 changes: 17 additions & 20 deletions e2e/tests/markdown/anchors.cy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
it(
'should render anchors and navigate correctly',
// this test is randomly failing on CI, so we need to retry it
{ retries: 3 },
() => {
cy.visit('/markdown/anchors.html')
const retries = 5

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

cy.get('.e2e-theme-content h1 > a')
.should('have.attr', 'class', 'header-anchor')
.should('have.attr', 'href', '#title')
.click()
cy.get('.e2e-theme-content h1')
.should('have.attr', 'id', 'title')
.should('have.attr', 'tabindex', '-1')

cy.hash().should('eq', '#title')
cy.get('.e2e-theme-content h1 > a')
.should('have.attr', 'class', 'header-anchor')
.should('have.attr', 'href', '#title')
.click()

cy.get('#anchor-1-1 > a')
.should('have.attr', 'class', 'header-anchor')
.click()
cy.hash().should('eq', '#title')

cy.hash().should('eq', '#anchor-1-1')
},
)
cy.get('#anchor-1-1 > a')
.should('have.attr', 'class', 'header-anchor')
.click()

cy.hash().should('eq', '#anchor-1-1')
})

0 comments on commit 524625f

Please sign in to comment.