[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

test: add test utils (#294)

authored by

James Garbutt and committed by
GitHub
(Apr 16, 2025, 10:01 AM +0100) fb55d6e9 93d7e44f

+41 -40
+2 -40
packages/prompts/src/index.test.ts
··· 1 - import { EventEmitter, Readable, Writable } from 'node:stream'; 1 + import { EventEmitter } from 'node:stream'; 2 2 import colors from 'picocolors'; 3 3 import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; 4 4 import * as prompts from './index.js'; 5 - 6 - // TODO (43081j): move this into a util? 7 - class MockWritable extends Writable { 8 - public buffer: string[] = []; 9 - 10 - _write( 11 - chunk: any, 12 - _encoding: BufferEncoding, 13 - callback: (error?: Error | null | undefined) => void 14 - ): void { 15 - this.buffer.push(chunk.toString()); 16 - callback(); 17 - } 18 - } 19 - 20 - class MockReadable extends Readable { 21 - protected _buffer: unknown[] | null = []; 22 - 23 - _read() { 24 - if (this._buffer === null) { 25 - this.push(null); 26 - return; 27 - } 28 - 29 - for (const val of this._buffer) { 30 - this.push(val); 31 - } 32 - 33 - this._buffer = []; 34 - } 35 - 36 - pushValue(val: unknown): void { 37 - this._buffer?.push(val); 38 - } 39 - 40 - close(): void { 41 - this._buffer = null; 42 - } 43 - } 5 + import { MockReadable, MockWritable } from './test-utils.js'; 44 6 45 7 describe.each(['true', 'false'])('prompts (isCI = %s)', (isCI) => { 46 8 let originalCI: string | undefined;
+39
packages/prompts/src/test-utils.ts
··· 1 + import { Readable, Writable } from 'node:stream'; 2 + 3 + export class MockWritable extends Writable { 4 + public buffer: string[] = []; 5 + 6 + _write( 7 + chunk: any, 8 + _encoding: BufferEncoding, 9 + callback: (error?: Error | null | undefined) => void 10 + ): void { 11 + this.buffer.push(chunk.toString()); 12 + callback(); 13 + } 14 + } 15 + 16 + export class MockReadable extends Readable { 17 + protected _buffer: unknown[] | null = []; 18 + 19 + _read() { 20 + if (this._buffer === null) { 21 + this.push(null); 22 + return; 23 + } 24 + 25 + for (const val of this._buffer) { 26 + this.push(val); 27 + } 28 + 29 + this._buffer = []; 30 + } 31 + 32 + pushValue(val: unknown): void { 33 + this._buffer?.push(val); 34 + } 35 + 36 + close(): void { 37 + this._buffer = null; 38 + } 39 + }