Skip to content

Commit

Permalink
test(fixture): improve finding ports to reduce flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Sep 8, 2023
1 parent 8f30255 commit 1fb7d6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"form-data": "4.0.0",
"fs-extra": "9.0.0",
"get-port": "5.1.1",
"get-port-please": "3.1.1",
"glob": "7.1.6",
"gzip-size": "5.1.1",
"html-validator": "5.1.18",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import path from 'path'
import spawn from 'cross-spawn'
import { writeFile } from 'fs-extra'
import getPort from 'get-port'
import { getRandomPort, checkPort } from 'get-port-please'
import fetch from 'node-fetch'
import qs from 'querystring'
import treeKill from 'tree-kill'
Expand Down Expand Up @@ -171,7 +172,18 @@ export function renderViaHTTP(
}

export function findPort() {
return getPort()
//[NOTE]: What are we doing here?
// There are some fixes related with flaky tests failures caused by `No available ports found`
// from 'get-port'. This may be related / fixed by upstream https://github.com/sindresorhus/get-port/pull/56,
// however it happened after get-port switched to pure esm which is not easy to adapt by bump.
// get-port-please seems to offer the feature parity so we'll try to use it, and leave get-port as fallback
// for a while until we are certain to switch to get-port-please entirely.
try {
return getRandomPort()
} catch (e) {
require('console').warn('get-port-please failed, falling back to get-port')
return getPort()
}
}

export interface NextOptions {
Expand Down

0 comments on commit 1fb7d6f

Please sign in to comment.