Unverified Commit 75441780 authored by Jude Gao's avatar Jude Gao Committed by GitHub

(e2e): improve app-hmr test stability (#72345)

parent 1b5c269a
import { nextTestSetup } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { retry, waitFor } from 'next-test-utils'
import path from 'path'
const envFile = '.env.development.local'
describe(`app-dir-hmr`, () => {
const { next } = nextTestSetup({
files: __dirname,
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
})
describe('filesystem changes', () => {
......@@ -60,9 +61,11 @@ describe(`app-dir-hmr`, () => {
await browser.eval('window.__TEST_NO_RELOAD = true')
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
await next.patchFile(envFile, 'MY_DEVICE="ipad"', async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
})
try {
const logs = await browser.log()
if (process.env.TURBOPACK) {
......@@ -131,13 +134,12 @@ describe(`app-dir-hmr`, () => {
},
])
}
} finally {
// TOOD: use sandbox instead
await next.patchFile(envFile, 'MY_DEVICE="mac"')
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
})
}
})
// ensure it's restored back to "mac" before the next test
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
})
})
it.each(['node', 'node-module-var', 'edge', 'edge-module-var'])(
......@@ -145,23 +147,22 @@ describe(`app-dir-hmr`, () => {
async (page) => {
const browser = await next.browser(`/env/${page}`)
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
let logs
await next.patchFile(envFile, 'MY_DEVICE="ipad"', async () => {
let logs
await retry(async () => {
logs = await browser.log()
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: '[Fast Refresh] rebuilding',
source: 'log',
}),
])
)
})
await retry(async () => {
logs = await browser.log()
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: '[Fast Refresh] rebuilding',
source: 'log',
}),
])
)
})
try {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
})
......@@ -186,14 +187,12 @@ describe(`app-dir-hmr`, () => {
])
)
}
} finally {
// TOOD: use sandbox instead
await next.patchFile(envFile, 'MY_DEVICE="mac"')
await retry(async () => {
console.log('checking...', await browser.elementByCss('p').text())
expect(await browser.elementByCss('p').text()).toBe('mac')
})
}
})
// ensure it's restored back to "mac" before the next test
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
})
}
)
......
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment