Waiting For Ports
Wait for the specified ports to become active.
waitForPortβ
import { waitForPort } from 'poku';
await waitForPort(3000, {
delay: 0,
interval: 100,
timeout: 60000,
host: 'localhost',
});
Options
export type WaitForPortOptions = {
/**
* Retry interval in milliseconds
*
* ---
*
* @default 100
*/
interval?: number;
/**
* Timeout in milliseconds
*
* ---
*
* @default 60000
*/
timeout?: number;
/**
* Delays both the start and end by the defined milliseconds.
*
* ---
*
* @default 0
*/
delay?: number;
/**
* Host to check the port on.
*
* ---
*
* @default "localhost"
*/
host?: string;
};
Examplesβ
Waiting for Multiple Portsβ
import { waitForPort } from 'poku';
await Promise.all([
waitForPort(3000),
waitForPort(4000),
waitForPort(5000),
waitForPort(6000),
]);
Waiting for a Container Service in Port 3000β
import { docker, waitForPort } from 'poku';
const compose = docker.compose();
await compose.up();
await waitForPort(3000, { delay: 100 });
const res = await fetch('http://localhost:3000');
/**
* Tests come here π§ͺ
*/
await compose.down();
tip
Poku exposes a minimal sleep
helper that just waits for milliseconds in addition to waitForPort
:
import { sleep } from 'poku';
// Wait for 1 second
await sleep(1000);