tests: fixed some test types and fixed darwin support (#65722)

This fixes some tests so that they can run on macOS that previously had
some issues with IPv6 during testing as well as updated some of the
tests to use `retry` over `check`.
This commit is contained in:
Wyatt Johnson 2024-06-10 13:31:05 -07:00 committed by GitHub
parent 996a290afd
commit edf8cc52fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 35 deletions

View file

@ -10,11 +10,12 @@ import {
initNextServerScript, initNextServerScript,
killApp, killApp,
} from 'next-test-utils' } from 'next-test-utils'
import { ChildProcess } from 'child_process'
describe('required server files app router', () => { describe('required server files app router', () => {
let next: NextInstance let next: NextInstance
let server let server: ChildProcess
let appPort let appPort: number | string
let delayedPostpone let delayedPostpone
let rewritePostpone let rewritePostpone
@ -93,7 +94,7 @@ describe('required server files app router', () => {
/- Local:/, /- Local:/,
{ {
...process.env, ...process.env,
PORT: appPort, PORT: `${appPort}`,
}, },
undefined, undefined,
{ {

View file

@ -12,6 +12,7 @@ import {
initNextServerScript, initNextServerScript,
killApp, killApp,
renderViaHTTP, renderViaHTTP,
retry,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
@ -134,11 +135,21 @@ describe('required server files', () => {
}, },
} }
) )
if (process.platform === 'darwin') {
appPort = `http://127.0.0.1:${appPort}`
}
} }
beforeAll(async () => { beforeAll(async () => {
await setupNext({ nextEnv: true, minimalMode: true }) await setupNext({ nextEnv: true, minimalMode: true })
}) })
beforeEach(() => {
errors = []
stderr = ''
})
afterAll(async () => { afterAll(async () => {
await next.destroy() await next.destroy()
if (server) await killApp(server) if (server) await killApp(server)
@ -958,60 +969,43 @@ describe('required server files', () => {
}) })
it('should bubble error correctly for gip page', async () => { it('should bubble error correctly for gip page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/errors/gip', { crash: '1' }) const res = await fetchViaHTTP(appPort, '/errors/gip', { crash: '1' })
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
await check( await retry(() => {
() => expect(errors.join('\n')).toInclude('gip hit an oops')
errors.join('\n').includes('gip hit an oops') })
? 'success'
: errors.join('\n'),
'success'
)
}) })
it('should bubble error correctly for gssp page', async () => { it('should bubble error correctly for gssp page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/errors/gssp', { crash: '1' }) const res = await fetchViaHTTP(appPort, '/errors/gssp', { crash: '1' })
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
await check(
() => await retry(() => {
errors.join('\n').includes('gssp hit an oops') expect(errors.join('\n')).toInclude('gssp hit an oops')
? 'success' })
: errors.join('\n'),
'success'
)
}) })
it('should bubble error correctly for gsp page', async () => { it('should bubble error correctly for gsp page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/errors/gsp/crash') const res = await fetchViaHTTP(appPort, '/errors/gsp/crash')
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
await check(
() => await retry(() => {
errors.join('\n').includes('gsp hit an oops') expect(errors.join('\n')).toInclude('gsp hit an oops')
? 'success' })
: errors.join('\n'),
'success'
)
}) })
it('should bubble error correctly for API page', async () => { it('should bubble error correctly for API page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/api/error') const res = await fetchViaHTTP(appPort, '/api/error')
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('Internal Server Error') expect(await res.text()).toBe('Internal Server Error')
await check(
() => await retry(() => {
errors.join('\n').includes('some error from /api/error') expect(errors.join('\n')).toInclude('some error from /api/error')
? 'success' })
: errors.join('\n'),
'success'
)
}) })
it('should normalize optional values correctly for SSP page', async () => { it('should normalize optional values correctly for SSP page', async () => {
@ -1284,6 +1278,7 @@ describe('required server files', () => {
expect(envVariables.envFromHost).toBe('FOOBAR') expect(envVariables.envFromHost).toBe('FOOBAR')
}) })
// FIXME: update to not mutate the global state
it('should run middleware correctly (without minimalMode, with wasm)', async () => { it('should run middleware correctly (without minimalMode, with wasm)', async () => {
const standaloneDir = join(next.testDir, 'standalone') const standaloneDir = join(next.testDir, 'standalone')