fs-teardown
Version:
Teardown API for testing file system-dependent code.
56 lines (55 loc) • 1.68 kB
TypeScript
/// <reference types="node" />
import { ExecOptions } from 'child_process';
export interface TeardownApi {
/**
* Creates a root directory. Emits the initial file tree,
* if provided.
*/
prepare(): Promise<string>;
/**
* Returns an absolute path to the file/directory.
*/
resolve(...segments: string[]): string;
/**
* Creates a file tree relative to the root directory.
*/
create(tree: FileTree): Promise<void>;
/**
* Reads a file at the given path.
*/
readFile(filePath: string): Promise<Buffer>;
readFile(filePath: string, encoding?: BufferEncoding): Promise<string>;
/**
* Edits a file at the given path.
*/
edit(filePath: string, nextContent: string): Promise<void>;
/**
* Executes the given command in the root directory.
*/
exec(command: string, options?: ExecOptions): Promise<{
stdout: string;
stderr: string;
}>;
/**
* Removes a file/directory at the given path.
*/
remove(filePath: string): Promise<void>;
/**
* Resets the root directory to the initial state.
* Reverts any runtime changes done to the file tree.
*/
reset(): Promise<void>;
/**
* Removes the root directory and all its files.
*/
cleanup(): Promise<void>;
}
export declare type FileContent = string;
export interface FileTree {
[path: string]: FileContent | FileTree | null;
}
export interface CreateTeardownOptions {
rootDir: string;
paths?: FileTree;
}
export declare function createTeardown(options: CreateTeardownOptions): TeardownApi;