sync-dev-server
Version:
Starts a server before your tests and stops on completion. Inspired by jest-puppeteer's subpackage jest-dev-server. Setup and teardown operations are fully synchronous.
44 lines (43 loc) • 1.6 kB
text/typescript
import * as child_process0 from "child_process";
import { ChildProcess } from "child_process";
//#region src/types.d.ts
type UsedPortAction = 'error' | 'ignore' | 'kill';
interface Options {
host?: string;
port?: number;
timeout?: number;
debug?: boolean;
signal?: string | number;
usedPortAction?: UsedPortAction;
env?: Record<string, string>;
isServerReadyFn?: (() => boolean) | null;
}
//#endregion
//#region src/dev.d.ts
/**
* Stops the given server
*
* @param {ChildProcess | null} server - The server's child process or null
* @param {number|string} [signal='SIGTERM'] - Signal to terminate the server
*/
declare const stopServer: (server: ChildProcess | null, signal?: number | string) => void;
/**
* Start a server process based on the provided command and options.
*
* @param {string} command - The command to start the server
* @param {Options} [options={}] - The options for starting the server
* @returns {ChildProcess | null} - The spawned server child process
*/
type StartServerReturn<T extends Options | undefined> = T extends {
usedPortAction: 'ignore';
} ? ChildProcess | null : ChildProcess;
declare function startServer<T extends Options | undefined = Options>(command: string, options?: T): StartServerReturn<T>;
//#endregion
//#region src/index.d.ts
declare const _default: {
startServer: typeof startServer;
stopServer: (server: child_process0.ChildProcess | null, signal?: number | string) => void;
};
//#endregion
export { type Options, type UsedPortAction, _default as default, startServer, stopServer };
//# sourceMappingURL=index.d.mts.map