@bomb.sh/tools
Version:
The internal dev, build, and lint CLI for Bombshell projects
38 lines (37 loc) • 1.32 kB
text/typescript
import { MockReadable, MockWritable } from "./stdio.mjs";
//#region src/test-utils/mock.d.ts
type InputConfig = true | ConstructorParameters<typeof MockReadable>[0];
type OutputConfig = true | ConstructorParameters<typeof MockWritable>[0];
interface CreateMockOptions {
/** Environment variables to set for the duration of the test. */
env?: Record<string, string | undefined>;
/** Pass `true` for defaults, or a config object. Omit to skip. */
input?: InputConfig;
/** Pass `true` for defaults, or a config object for columns/rows/isTTY. */
output?: OutputConfig;
}
type Mocks<O extends CreateMockOptions = CreateMockOptions> = {
input: O["input"] extends InputConfig ? MockReadable : undefined;
output: O["output"] extends OutputConfig ? MockWritable : undefined;
};
/**
* Create a mock test environment with streams, env vars.
*
* Cleanup is automatic via `onTestFinished` — no `beforeAll`/`afterAll` needed.
*
* @example
* ```ts
* let mocks: Mocks;
* beforeEach(() => {
* mocks = createMocks({ env: { CI: 'true' }});
* });
*
* it('works', () => {
* doThing(mocks.input, mocks.output);
* });
* ```
*/
declare function createMocks<O extends CreateMockOptions>(opts?: O): Mocks<O>;
//#endregion
export { CreateMockOptions, Mocks, createMocks };
//# sourceMappingURL=mock.d.mts.map