Skip to content

Commit

Permalink
make test case more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Dec 13, 2021
1 parent 96c73da commit 83c69a9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions test/integration/app-document-add-hmr/test/index.test.js
Expand Up @@ -7,7 +7,6 @@ import { killApp, findPort, launchApp, check } from 'next-test-utils'

const appDir = join(__dirname, '../')
const appPage = join(appDir, 'pages/_app.js')
const indexPage = join(appDir, 'pages/index.js')
const documentPage = join(appDir, 'pages/_document.js')

let appPort
Expand All @@ -21,10 +20,8 @@ describe('_app/_document add HMR', () => {
afterAll(() => killApp(app))

it('should HMR when _app is added', async () => {
let indexContent = await fs.readFile(indexPage)
const browser = await webdriver(appPort, '/')
try {
const browser = await webdriver(appPort, '/')

const html = await browser.eval('document.documentElement.innerHTML')
expect(html).not.toContain('custom _app')
expect(html).toContain('index page')
Expand All @@ -50,16 +47,19 @@ describe('_app/_document add HMR', () => {
: html
}, 'success')
} finally {
await fs.writeFile(indexPage, indexContent)
await fs.remove(appPage)
await check(async () => {
const html = await browser.eval('document.documentElement.innerHTML')
return !html.includes('custom _app') && html.includes('index page')
? 'restored'
: html
}, 'restored')
}
})

it('should HMR when _document is added', async () => {
let indexContent = await fs.readFile(indexPage)
const browser = await webdriver(appPort, '/')
try {
const browser = await webdriver(appPort, '/')

const html = await browser.eval('document.documentElement.innerHTML')
expect(html).not.toContain('custom _document')
expect(html).toContain('index page')
Expand Down Expand Up @@ -101,8 +101,13 @@ describe('_app/_document add HMR', () => {
: html
}, 'success')
} finally {
await fs.writeFile(indexPage, indexContent)
await fs.remove(documentPage)
await check(async () => {
const html = await browser.eval('document.documentElement.innerHTML')
return !html.includes('custom _document') && html.includes('index page')
? 'restored'
: html
}, 'restored')
}
})
})

0 comments on commit 83c69a9

Please sign in to comment.