Skip to content

Commit

Permalink
Remove portfinder from NextJS tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Jul 22, 2023
1 parent 6ae5375 commit 3d3812e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/nextjs/test/integration/test/server/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 });
});
Expand All @@ -39,7 +40,6 @@ export class NextTestEnv extends TestEnv {
}

public static async init(): Promise<NextTestEnv> {
const port = await getPortPromise();
const server = await createNextServer({
dev: false,
dir: path.resolve(__dirname, '../../..'),
Expand All @@ -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);
}
}

0 comments on commit 3d3812e

Please sign in to comment.