@@ -5,7 +5,7 @@ import fs from "node:fs/promises";
55import os from "node:os" ;
66import path from "node:path" ;
77import { PassThrough } from "node:stream" ;
8- import { formatFile , formatFiles , mainFormatStdin } from "../cli/cli.js" ;
8+ import { formatFile , formatFiles , main , mainFormatStdin } from "../cli/cli.js" ;
99import type {
1010 CLI ,
1111 EditorConfigOptions ,
@@ -67,6 +67,9 @@ suite("CLI", () => {
6767
6868 assert . equal ( didChange , true ) ;
6969 assert . equal ( actual , "content" ) ;
70+ assert . deepEqual ( logger . getEntries ( ) , [
71+ { level : "log" , message : fileName } ,
72+ ] ) ;
7073 } finally {
7174 await cleanupTempFile ( fileName ) ;
7275 }
@@ -301,6 +304,74 @@ suite("CLI", () => {
301304 assert . equal ( output . text , "[warn] Code style issues found in stdin.\n" ) ;
302305 } ) ;
303306
307+ test ( "Captures check-mode file entries without writing when quiet" , async ( ) => {
308+ const fileName = await createTempFile (
309+ "talonfmt-" ,
310+ "example.txt" ,
311+ "content" ,
312+ ) ;
313+ const cli = createCLI ( ( text ) => `${ text } updated` ) ;
314+ const logger = createLogger ( true ) ;
315+
316+ try {
317+ const stdout = await captureStreamWrite ( process . stdout , async ( ) =>
318+ formatFile ( {
319+ cli,
320+ logger,
321+ check : true ,
322+ debug : false ,
323+ filePath : fileName ,
324+ } ) ,
325+ ) ;
326+ const stderr = await captureStreamWrite ( process . stderr , async ( ) =>
327+ Promise . resolve ( ) ,
328+ ) ;
329+
330+ assert . equal ( stdout . result , true ) ;
331+ assert . equal ( stdout . text , "" ) ;
332+ assert . equal ( stderr . text , "" ) ;
333+ assert . deepEqual ( logger . getEntries ( ) , [
334+ { level : "log" , message : fileName } ,
335+ ] ) ;
336+ } finally {
337+ await cleanupTempFile ( fileName ) ;
338+ }
339+ } ) ;
340+
341+ test ( "Check mode reports summary and changed file paths" , async ( ) => {
342+ const fileName = await createTempFile (
343+ "talonfmt-" ,
344+ "example.txt" ,
345+ "content" ,
346+ ) ;
347+ const cli = createCLI ( ( text ) => `${ text } updated` ) ;
348+ const originalArgv = process . argv ;
349+ const originalExitCode = process . exitCode ;
350+
351+ try {
352+ process . argv = [ "node" , "talon-fmt" , "--check" , fileName ] ;
353+
354+ const output = await captureStdoutAndStderr ( async ( ) => {
355+ await main ( cli ) ;
356+ return process . exitCode ;
357+ } ) ;
358+
359+ assert . equal ( output . result , EXIT_FAIL ) ;
360+ assert . equal (
361+ output . stdoutText ,
362+ [ "Checking formatting..." , `${ fileName } ` , "" ] . join ( "\n" ) ,
363+ ) ;
364+ assert . equal (
365+ output . stderrText ,
366+ "[warn] Code style issues found in 1 file(s).\n" ,
367+ ) ;
368+ } finally {
369+ process . argv = originalArgv ;
370+ process . exitCode = originalExitCode ;
371+ await cleanupTempFile ( fileName ) ;
372+ }
373+ } ) ;
374+
304375 test ( "Returns success for unchanged stdin in check mode" , async ( ) => {
305376 const cli = createCLI ( ( text ) => text ) ;
306377 const logger = createLogger ( ) ;
@@ -606,6 +677,37 @@ async function captureStreamWrite<T>(
606677 }
607678}
608679
680+ async function captureStdoutAndStderr < T > (
681+ callback : ( ) => Promise < T > ,
682+ ) : Promise < { result : T ; stdoutText : string ; stderrText : string } > {
683+ let stdoutText = "" ;
684+ let stderrText = "" ;
685+ const originalStdoutWrite = process . stdout . write . bind ( process . stdout ) ;
686+ const originalStderrWrite = process . stderr . write . bind ( process . stderr ) ;
687+
688+ ( process . stdout . write as unknown as ( chunk : string ) => boolean ) = (
689+ chunk : string | Uint8Array ,
690+ ) => {
691+ stdoutText += chunk . toString ( ) ;
692+ return true ;
693+ } ;
694+
695+ ( process . stderr . write as unknown as ( chunk : string ) => boolean ) = (
696+ chunk : string | Uint8Array ,
697+ ) => {
698+ stderrText += chunk . toString ( ) ;
699+ return true ;
700+ } ;
701+
702+ try {
703+ const result = await callback ( ) ;
704+ return { result, stdoutText, stderrText } ;
705+ } finally {
706+ process . stdout . write = originalStdoutWrite ;
707+ process . stderr . write = originalStderrWrite ;
708+ }
709+ }
710+
609711function getArguments ( args : Partial < ParsedArgs > ) {
610712 return {
611713 ...getDefaultArguments ( ) ,
0 commit comments