From 3d3812e9c3254fcf6b6413002bd5e08e6a6be43b 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. --- .../test/integration/test/server/utils/helpers.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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); } }