From 5f6316b7c897dc33b0f34ea8055c0ef0ce8307d8 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Sat, 22 Jul 2023 11:13:41 +0000 Subject: [PATCH] Remove `portfinder` from NextJS tests. --- .github/workflows/build.yml | 2 +- .../test/integration/test/server/utils/helpers.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c024683bd4e..438c7152defa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -430,7 +430,7 @@ jobs: strategy: fail-fast: false matrix: - node: [10, 12, 14, 16, 18] + node: [10, 12, 14, 16, 18, 20] steps: - name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }}) uses: actions/checkout@v3 diff --git a/packages/nextjs/test/integration/test/server/utils/helpers.ts b/packages/nextjs/test/integration/test/server/utils/helpers.ts index c7213785493f..efc8c144eee2 100644 --- a/packages/nextjs/test/integration/test/server/utils/helpers.ts +++ b/packages/nextjs/test/integration/test/server/utils/helpers.ts @@ -1,10 +1,10 @@ -import { getPortPromise } from 'portfinder'; import { TestEnv } from '../../../../../../node-integration-tests/utils'; import * as http from 'http'; import * as path from 'path'; import { createServer, Server } from 'http'; import { parse } from 'url'; import next from 'next'; +import { AddressInfo } from 'net'; // Type not exported from NextJS // @ts-ignore @@ -24,9 +24,10 @@ export const createNextServer = async config => { }); }; -export const startServer = async (server: Server, port: string | number) => { - return new Promise(resolve => { - server.listen(port || 0, () => { +export const startServer = async (server: Server) => { + return new Promise<{ server: http.Server; url: string }>(resolve => { + server.listen(0, () => { + const port = (server.address() as AddressInfo).port; const url = `http://localhost:${port}`; resolve({ server, url }); }); @@ -39,7 +40,6 @@ export class NextTestEnv extends TestEnv { } public static async init(): Promise { - const port = await getPortPromise(); const server = await createNextServer({ dev: false, dir: path.resolve(__dirname, '../../..'), @@ -50,8 +50,8 @@ export class NextTestEnv extends TestEnv { conf: path.resolve(__dirname, '../../next.config.js'), }); - await startServer(server, port); + const { url } = await startServer(server); - return new NextTestEnv(server, `http://localhost:${port}`); + return new NextTestEnv(server, url); } }