remove get-free-port

This commit is contained in:
Simon Knott 2025-01-23 15:55:41 +01:00
parent a4d4b5a2a2
commit 3d89657695
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 3 additions and 14 deletions

View file

@ -130,8 +130,9 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
if (typeof mockingProxyOption.port === 'number' && testInfoImpl.config.workers > 1)
throw new Error(`Cannot share mocking proxy between multiple workers. Either disable parallel mode or set mockingProxy.port to 'inject'`);
const port = typeof mockingProxyOption.port === 'number' ? mockingProxyOption.port : await getFreePort();
const mockingProxy = await playwright.mockingProxy.newProxy(port);
const mockingProxy = await playwright.mockingProxy.newProxy(
mockingProxyOption.port === 'inject' ? undefined : mockingProxyOption.port
);
await use(mockingProxy);
}, { scope: 'worker' }],

View file

@ -398,15 +398,3 @@ export async function removeDirAndLogToConsole(dir: string) {
} catch {
}
}
export async function getFreePort() {
const promise = new ManualPromise<number>();
const server = net.createServer();
server.unref();
server.on('error', promise.reject);
server.listen(0, () => {
const { port } = server.address() as AddressInfo;
server.close(() => promise.resolve(port));
});
return promise;
}