mirror of
https://github.com/voson-wang/toon.git
synced 2026-01-29 23:34:10 +08:00
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:
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user