From 83c69a9d4e66b7bd842a79a567544b04251aa3a7 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 13 Dec 2021 17:42:46 +0100 Subject: [PATCH] make test case more stable --- .../app-document-add-hmr/test/index.test.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/test/integration/app-document-add-hmr/test/index.test.js b/test/integration/app-document-add-hmr/test/index.test.js index ac7c86769c4f229..af24d990203a246 100644 --- a/test/integration/app-document-add-hmr/test/index.test.js +++ b/test/integration/app-document-add-hmr/test/index.test.js @@ -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 @@ -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') @@ -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') @@ -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') } }) })