Unverified Commit ed267869 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

test: move HMR basic test to a separate file (#73612)

> [!NOTE]
> The "Test new tests for flakes" may fail due to the number of tests in
a single `hmr.test.ts` file.
> The follow-up stacks are to resolve the issue.

### Why?

Moved to a separate file to run the test in parallel.
parent 02d5294c
import { join } from 'path'
import webdriver from 'next-webdriver'
import { import {
assertHasRedbox, assertHasRedbox,
getBrowserBodyText, getBrowserBodyText,
retry, retry,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
import { createNext } from 'e2e-utils' import { createNext, nextTestSetup } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import type { NextConfig } from 'next' import type { NextConfig } from 'next'
describe.each([ describe.each([
...@@ -16,28 +13,20 @@ describe.each([ ...@@ -16,28 +13,20 @@ describe.each([
{ basePath: '/docs', assetPrefix: '' }, { basePath: '/docs', assetPrefix: '' },
{ basePath: '/docs', assetPrefix: '/asset-prefix' }, { basePath: '/docs', assetPrefix: '/asset-prefix' },
])('basic HMR, nextConfig: %o', (nextConfig: Partial<NextConfig>) => { ])('basic HMR, nextConfig: %o', (nextConfig: Partial<NextConfig>) => {
const { basePath } = nextConfig const { next } = nextTestSetup({
let next: NextInstance files: __dirname,
nextConfig,
beforeAll(async () => { patchFileDelay: 500,
next = await createNext({
files: join(__dirname, 'hmr'),
nextConfig,
patchFileDelay: 500,
})
}) })
afterAll(() => next.destroy()) const { basePath } = nextConfig
it('should have correct router.isReady for auto-export page', async () => { it('should have correct router.isReady for auto-export page', async () => {
let browser = await webdriver(next.url, basePath + '/auto-export-is-ready') let browser = await next.browser(basePath + '/auto-export-is-ready')
expect(await browser.elementByCss('#ready').text()).toBe('yes') expect(await browser.elementByCss('#ready').text()).toBe('yes')
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({}) expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({})
browser = await webdriver( browser = await next.browser(basePath + '/auto-export-is-ready?hello=world')
next.url,
basePath + '/auto-export-is-ready?hello=world'
)
await retry(async () => { await retry(async () => {
expect(await browser.elementByCss('#ready').text()).toBe('yes') expect(await browser.elementByCss('#ready').text()).toBe('yes')
...@@ -48,12 +37,12 @@ describe.each([ ...@@ -48,12 +37,12 @@ describe.each([
}) })
it('should have correct router.isReady for getStaticProps page', async () => { it('should have correct router.isReady for getStaticProps page', async () => {
let browser = await webdriver(next.url, basePath + '/gsp-is-ready') let browser = await next.browser(basePath + '/gsp-is-ready')
expect(await browser.elementByCss('#ready').text()).toBe('yes') expect(await browser.elementByCss('#ready').text()).toBe('yes')
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({}) expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({})
browser = await webdriver(next.url, basePath + '/gsp-is-ready?hello=world') browser = await next.browser(basePath + '/gsp-is-ready?hello=world')
await retry(async () => { await retry(async () => {
expect(await browser.elementByCss('#ready').text()).toBe('yes') expect(await browser.elementByCss('#ready').text()).toBe('yes')
...@@ -68,10 +57,7 @@ describe.each([ ...@@ -68,10 +57,7 @@ describe.each([
const originalContent = await next.readFile(pageName) const originalContent = await next.readFile(pageName)
try { try {
const browser = await webdriver( const browser = await next.browser(basePath + '/auto-export-is-ready')
next.url,
basePath + '/auto-export-is-ready'
)
const outputLength = next.cliOutput.length const outputLength = next.cliOutput.length
await next.patchFile( await next.patchFile(
pageName, pageName,
...@@ -101,9 +87,7 @@ describe.each([ ...@@ -101,9 +87,7 @@ describe.each([
}) })
it('should reload the page when the server restarts', async () => { it('should reload the page when the server restarts', async () => {
const browser = await webdriver(next.url, basePath + '/hmr/about', { const browser = await next.browser(basePath + '/hmr/about')
headless: false,
})
await retry(async () => { await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch( expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/ /This is the about page/
...@@ -120,12 +104,13 @@ describe.each([ ...@@ -120,12 +104,13 @@ describe.each([
}) })
}) })
next = await createNext({ const secondNext = await createNext({
files: join(__dirname, 'hmr'), files: __dirname,
nextConfig, nextConfig,
forcedPort: next.appPort, forcedPort: next.appPort,
}) })
await reloadPromise await reloadPromise
await secondNext.destroy()
}) })
}) })
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