Skip to content

Commit

Permalink
use random port provided by express (#21283)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWatanabe authored Jan 14, 2022
1 parent e26ce6e commit a199d0d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scripts/projects-test/performBrowserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import config from '../config';
import { safeLaunchOptions } from '../puppeteer/puppeteer.config';
import express from 'express';
import http from 'http';
import portfinder from 'portfinder';
import puppeteer from 'puppeteer';
import { AddressInfo } from 'net';

function startServer(publicDirectory: string, listenPort: number) {
return new Promise<http.Server>((resolve, reject) => {
Expand All @@ -23,9 +23,10 @@ function startServer(publicDirectory: string, listenPort: number) {
}

export async function performBrowserTest(publicDirectory: string) {
const listenPort = await portfinder.getPortPromise();
console.log(`Starting server on port ${listenPort} from directory ${publicDirectory}`);
const server = await startServer(publicDirectory, listenPort);
const server = await startServer(publicDirectory, 0);
const { port } = server.address() as AddressInfo;

console.log(`Starting server on port ${port} from directory ${publicDirectory}`);
console.log('Started server. Launching Puppeteer...');

const options = safeLaunchOptions();
Expand Down Expand Up @@ -58,7 +59,7 @@ export async function performBrowserTest(publicDirectory: string) {
error = pageError;
});

const url = `http://${config.server_host}:${listenPort}`;
const url = `http://${config.server_host}:${port}`;
console.log(`Loading ${url} in puppeteer...`);
await page.goto(url);
console.log('Page loaded');
Expand Down

0 comments on commit a199d0d

Please sign in to comment.