test(cli): add tests for stdin input (#107)

* test(cli): add tests for stdin input

* test(cli): extract mock stdin to helper function

* test(cli): add comprehensive tests for stdin edge cases and output file handling

* refactor(test): streamline mockStdin function and relocate to utils

* test(cli): remove redundant test for JSON encoding from stdin

* test(cli): restore mocks consistently

* test(cli):  restructured output file tests and modified some assertions

* chore: fix linting issues & remove redundant cleanups

---------

Co-authored-by: mad-cat-lon <113548315+mad-cat-lon@users.noreply.github.com>
Co-authored-by: Johann Schopplich <mail@johannschopplich.com>
This commit is contained in:
cy
2025-11-11 11:35:52 -05:00
committed by GitHub
parent 0a4c89e496
commit f798bba095
2 changed files with 210 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import * as fsp from 'node:fs/promises'
import * as os from 'node:os'
import * as path from 'node:path'
import process from 'node:process'
import { Readable } from 'node:stream'
import { runMain } from 'citty'
import { mainCommand } from '../src/index'
@@ -76,3 +77,20 @@ async function writeFiles(baseDir: string, files: FileRecord): Promise<void> {
}),
)
}
export function mockStdin(input: string): () => void {
const mockStream = Readable.from([input])
const originalStdin = process.stdin
Object.defineProperty(process, 'stdin', {
value: mockStream,
writable: true,
})
return () => {
Object.defineProperty(process, 'stdin', {
value: originalStdin,
writable: true,
})
}
}