@push-based/node-cli-testing
Version:
### A e2e-testing library for node CLI and processes including sandbox generation on the fly
85 lines (84 loc) • 2.58 kB
TypeScript
import { CliProcess, FileOrFolderMap, ProcessParams, ProcessTestOptions, ProjectConfig } from './types';
import { ProcessOptions, PromptTestOptions, TestResult } from '../../../process/src/index';
/**
* A closure for the testProcessE2e function to seperate process configuration and testing config from test data.
*
* @param processOptions: passed directly to execa as options
*/
export declare function getCliProcess(processOptions: ProcessOptions, promptTestOptions: PromptTestOptions & ProcessTestOptions): CliProcess;
/**
* A helper class to manage an project structure for a yargs based CLI
*/
export declare class CliProject<RcConfig extends {}> {
/**
* A flag to add more detailed information as logs
*/
protected verbose: boolean;
/**
* The folder in which to execute the process
*/
root: string;
/**
* The the binary to execute
*/
protected bin: string;
/**
* The process executing the CLI bin
*/
protected process: CliProcess;
/**
* Filenames to delete e.g. in project teardown
* All files are located from root
*/
protected deleteFiles: string[];
/**
* Filenames to create e.g. in project setup
* All files are located from root
*/
protected createFiles: FileOrFolderMap;
/**
* Filenames to create e.g. in project setup
*/
protected rcFile: Record<string, RcConfig>;
constructor();
/**
* freezes jest so we can read logs :)
* @param ms
*/
wait(ms?: number): Promise<void>;
logVerbose(...args: any): void;
tableVerbose(...args: any): void;
_setup(cfg: ProjectConfig<RcConfig>): Promise<void>;
/**
* @internal
* @protected
*
* Method to delete files generated during the CLI run
* Notice all files will get located from the project root
*/
deleteGeneratedFiles(): void;
/**
* @internal
* @protected
*
* Method to create files needed during the CLI run
* Notice all files will get located from the project root
*/
createInitialFiles(): void;
/**
* Set up the project. e.g. create files, start processes
*/
setup(): Promise<void>;
/**
* Teardown the project. e.g delete files, stop processes
*/
teardown(): Promise<void>;
/**
* Executes the CLI with given parameters and user input.
* See getCliProcess for details
*
* @param processParams
* @param userInput
*/
exec(processParams?: ProcessParams, userInput?: string[]): Promise<TestResult>;
}