Skip to content

Commit edf8cc5

Browse files
authored
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`.
1 parent 996a290 commit edf8cc5

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import {
1010
initNextServerScript,
1111
killApp,
1212
} from 'next-test-utils'
13+
import { ChildProcess } from 'child_process'
1314

1415
describe('required server files app router', () => {
1516
let next: NextInstance
16-
let server
17-
let appPort
17+
let server: ChildProcess
18+
let appPort: number | string
1819
let delayedPostpone
1920
let rewritePostpone
2021

@@ -93,7 +94,7 @@ describe('required server files app router', () => {
9394
/- Local:/,
9495
{
9596
...process.env,
96-
PORT: appPort,
97+
PORT: `${appPort}`,
9798
},
9899
undefined,
99100
{

test/production/standalone-mode/required-server-files/required-server-files.test.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
initNextServerScript,
1313
killApp,
1414
renderViaHTTP,
15+
retry,
1516
waitFor,
1617
} from 'next-test-utils'
1718

@@ -134,11 +135,21 @@ describe('required server files', () => {
134135
},
135136
}
136137
)
138+
139+
if (process.platform === 'darwin') {
140+
appPort = `http://127.0.0.1:${appPort}`
141+
}
137142
}
138143

139144
beforeAll(async () => {
140145
await setupNext({ nextEnv: true, minimalMode: true })
141146
})
147+
148+
beforeEach(() => {
149+
errors = []
150+
stderr = ''
151+
})
152+
142153
afterAll(async () => {
143154
await next.destroy()
144155
if (server) await killApp(server)
@@ -958,60 +969,43 @@ describe('required server files', () => {
958969
})
959970

960971
it('should bubble error correctly for gip page', async () => {
961-
errors = []
962972
const res = await fetchViaHTTP(appPort, '/errors/gip', { crash: '1' })
963973
expect(res.status).toBe(500)
964974
expect(await res.text()).toBe('Internal Server Error')
965975

966-
await check(
967-
() =>
968-
errors.join('\n').includes('gip hit an oops')
969-
? 'success'
970-
: errors.join('\n'),
971-
'success'
972-
)
976+
await retry(() => {
977+
expect(errors.join('\n')).toInclude('gip hit an oops')
978+
})
973979
})
974980

975981
it('should bubble error correctly for gssp page', async () => {
976-
errors = []
977982
const res = await fetchViaHTTP(appPort, '/errors/gssp', { crash: '1' })
978983
expect(res.status).toBe(500)
979984
expect(await res.text()).toBe('Internal Server Error')
980-
await check(
981-
() =>
982-
errors.join('\n').includes('gssp hit an oops')
983-
? 'success'
984-
: errors.join('\n'),
985-
'success'
986-
)
985+
986+
await retry(() => {
987+
expect(errors.join('\n')).toInclude('gssp hit an oops')
988+
})
987989
})
988990

989991
it('should bubble error correctly for gsp page', async () => {
990-
errors = []
991992
const res = await fetchViaHTTP(appPort, '/errors/gsp/crash')
992993
expect(res.status).toBe(500)
993994
expect(await res.text()).toBe('Internal Server Error')
994-
await check(
995-
() =>
996-
errors.join('\n').includes('gsp hit an oops')
997-
? 'success'
998-
: errors.join('\n'),
999-
'success'
1000-
)
995+
996+
await retry(() => {
997+
expect(errors.join('\n')).toInclude('gsp hit an oops')
998+
})
1001999
})
10021000

10031001
it('should bubble error correctly for API page', async () => {
1004-
errors = []
10051002
const res = await fetchViaHTTP(appPort, '/api/error')
10061003
expect(res.status).toBe(500)
10071004
expect(await res.text()).toBe('Internal Server Error')
1008-
await check(
1009-
() =>
1010-
errors.join('\n').includes('some error from /api/error')
1011-
? 'success'
1012-
: errors.join('\n'),
1013-
'success'
1014-
)
1005+
1006+
await retry(() => {
1007+
expect(errors.join('\n')).toInclude('some error from /api/error')
1008+
})
10151009
})
10161010

10171011
it('should normalize optional values correctly for SSP page', async () => {
@@ -1284,6 +1278,7 @@ describe('required server files', () => {
12841278
expect(envVariables.envFromHost).toBe('FOOBAR')
12851279
})
12861280

1281+
// FIXME: update to not mutate the global state
12871282
it('should run middleware correctly (without minimalMode, with wasm)', async () => {
12881283
const standaloneDir = join(next.testDir, 'standalone')
12891284

0 commit comments

Comments
 (0)