@@ -46,6 +46,21 @@ const runCLI = (args: string[]) => {
4646
4747const runFmt = ( args : string [ ] = [ ] ) => runCLI ( [ 'fmt' , ...args ] ) ;
4848
49+ const normalizeDuration = ( output : string ) : string =>
50+ output . replace ( / \d + m (?: \d + (?: \. \d + ) ? s ) ? | \d + (?: \. \d + ) ? s / g, '<duration>' ) ;
51+
52+ const expectWriteSummary = (
53+ output : string ,
54+ matchedFileCount : number ,
55+ writtenCount : number ,
56+ ) : void => {
57+ const files = matchedFileCount === 1 ? 'file' : 'files' ;
58+ const message = writtenCount
59+ ? `Formatted ${ writtenCount } of ${ matchedFileCount } ${ files } in <duration>.`
60+ : `Checked ${ matchedFileCount } ${ files } in <duration>. No changes needed.` ;
61+ expect ( normalizeDuration ( output ) ) . toBe ( `success ${ message } \n` ) ;
62+ } ;
63+
4964beforeEach ( ( ) => {
5065 projectPath = mkdtempSync ( path . join ( import . meta. dirname , 'test-temp-fmt-' ) ) ;
5166 // Prevent repository-level ignore rules from affecting the fixture.
@@ -76,7 +91,7 @@ test('supports format as an alias for fmt', () => {
7691 const result = runCLI ( [ 'format' , 'index.ts' ] ) ;
7792
7893 expect ( result . status ) . toBe ( 0 ) ;
79- expect ( result . stdout ) . toBe ( 'success index.ts\n' ) ;
94+ expectWriteSummary ( result . stdout , 1 , 1 ) ;
8095 expect ( result . stderr ) . toBe ( '' ) ;
8196 expect ( readProjectFile ( 'index.ts' ) ) . toBe ( 'const message = "hello";\n' ) ;
8297} ) ;
@@ -97,11 +112,21 @@ test('formats the current directory with Prettier defaults', () => {
97112 const result = runFmt ( ) ;
98113
99114 expect ( result . status ) . toBe ( 0 ) ;
100- expect ( result . stdout ) . toBe ( 'success index.ts\n' ) ;
115+ expectWriteSummary ( result . stdout , 2 , 1 ) ;
101116 expect ( result . stderr ) . toBe ( '' ) ;
102117 expect ( readProjectFile ( 'index.ts' ) ) . toBe ( 'const message = "hello";\n' ) ;
103118} ) ;
104119
120+ test ( 'summarizes write mode when no files change' , ( ) => {
121+ writeProjectFile ( 'index.ts' , 'const message = "hello";\n' ) ;
122+
123+ const result = runFmt ( [ 'index.ts' ] ) ;
124+
125+ expect ( result . status ) . toBe ( 0 ) ;
126+ expectWriteSummary ( result . stdout , 1 , 0 ) ;
127+ expect ( result . stderr ) . toBe ( '' ) ;
128+ } ) ;
129+
105130test ( 'does not sort package.json by default' , ( ) => {
106131 writeProjectFile ( 'package.json' , packageJsonSource ) ;
107132
@@ -139,7 +164,7 @@ test('supports configuring the worker count', () => {
139164 const result = runFmt ( [ '--parallel-workers' , '1' , 'first.ts' , 'second.ts' ] ) ;
140165
141166 expect ( result . status ) . toBe ( 0 ) ;
142- expect ( result . stdout ) . toBe ( 'success first.ts\nsuccess second.ts\n' ) ;
167+ expectWriteSummary ( result . stdout , 2 , 2 ) ;
143168 expect ( result . stderr ) . toBe ( '' ) ;
144169 expect ( readProjectFile ( 'first.ts' ) ) . toBe ( 'const first = "first";\n' ) ;
145170 expect ( readProjectFile ( 'second.ts' ) ) . toBe ( 'const second = "second";\n' ) ;
@@ -154,7 +179,7 @@ test('does not load Prettier config or ignore files', () => {
154179 const result = runFmt ( [ 'index.ts' ] ) ;
155180
156181 expect ( result . status ) . toBe ( 0 ) ;
157- expect ( result . stdout ) . toBe ( 'success index.ts\n' ) ;
182+ expectWriteSummary ( result . stdout , 1 , 1 ) ;
158183 expect ( result . stderr ) . toBe ( '' ) ;
159184 expect ( readProjectFile ( 'index.ts' ) ) . toBe ( 'function getMessage() {\n return "hello";\n}\n' ) ;
160185} ) ;
@@ -186,7 +211,7 @@ define.fmt({
186211 const result = runFmt ( [ '--write' , 'src/**/*.ts' ] ) ;
187212
188213 expect ( result . status ) . toBe ( 0 ) ;
189- expect ( result . stdout ) . toBe ( 'success src/index.test.ts\nsuccess src/index.ts\n' ) ;
214+ expectWriteSummary ( result . stdout , 2 , 2 ) ;
190215 expect ( result . stderr ) . toBe ( '' ) ;
191216 expect ( readProjectFile ( 'src/index.ts' ) ) . toBe ( "const message = 'hello';\n" ) ;
192217 expect ( readProjectFile ( 'src/index.test.ts' ) ) . toBe ( "const test = 'test'\n" ) ;
@@ -209,7 +234,7 @@ define.fmt({
209234 const result = runFmt ( [ 'index.ts' , '--config' , 'custom.config.ts' ] ) ;
210235
211236 expect ( result . status ) . toBe ( 0 ) ;
212- expect ( result . stdout ) . toBe ( 'success index.ts\n' ) ;
237+ expectWriteSummary ( result . stdout , 1 , 1 ) ;
213238 expect ( result . stderr ) . toBe ( '' ) ;
214239 expect ( readProjectFile ( 'index.ts' ) ) . toBe ( "const message = 'hello';\n" ) ;
215240} ) ;
@@ -221,19 +246,21 @@ test('checks formatting without writing files', () => {
221246 const result = runFmt ( [ '--check' , 'index.ts' ] ) ;
222247
223248 expect ( result . status ) . toBe ( 1 ) ;
224- expect ( result . stdout ) . toBe ( 'start Checking formatting...\n' ) ;
249+ expect ( normalizeDuration ( result . stdout ) ) . toBe (
250+ 'start Checking formatting...\ninfo Checked 1 file in <duration>.\n' ,
251+ ) ;
225252 expect ( result . stderr ) . toContain ( 'error index.ts' ) ;
226- expect ( result . stderr ) . toContain (
227- 'error Code style issues found in 1 file. Run rs fmt --write to fix.' ,
253+ expect ( normalizeDuration ( result . stderr ) ) . toContain (
254+ 'error Formatting issues found in 1 file. Run without --check to fix.' ,
228255 ) ;
229256 expect ( readProjectFile ( 'index.ts' ) ) . toBe ( source ) ;
230257
231258 writeProjectFile ( 'index.ts' , 'const message = "hello";\n' ) ;
232259 const formattedResult = runFmt ( [ '--check' , 'index.ts' ] ) ;
233260
234261 expect ( formattedResult . status ) . toBe ( 0 ) ;
235- expect ( formattedResult . stdout ) . toBe (
236- 'start Checking formatting...\nsuccess All matched files are correctly formatted .\n' ,
262+ expect ( normalizeDuration ( formattedResult . stdout ) ) . toBe (
263+ 'start Checking formatting...\nsuccess Checked 1 file in <duration>. No issues found .\n' ,
237264 ) ;
238265 expect ( formattedResult . stderr ) . toBe ( '' ) ;
239266} ) ;
@@ -278,7 +305,7 @@ define.fmt({
278305 const result = runFmt ( [ '*.fixture' ] ) ;
279306
280307 expect ( result . status ) . toBe ( 0 ) ;
281- expect ( result . stdout ) . toBe ( 'success first.fixture\nsuccess second.fixture\n' ) ;
308+ expectWriteSummary ( result . stdout , 2 , 2 ) ;
282309 expect ( result . stderr ) . toBe ( '' ) ;
283310 expect ( readProjectFile ( 'first.fixture' ) ) . toBe ( '{ "first": true }\n' ) ;
284311 expect ( readProjectFile ( 'second.fixture' ) ) . toBe ( '{ "second": true }\n' ) ;
@@ -306,7 +333,7 @@ define.fmt({
306333 const result = runFmt ( [ 'data.fixture' , 'index.ts' ] ) ;
307334
308335 expect ( result . status ) . toBe ( 0 ) ;
309- expect ( result . stdout ) . toBe ( 'success data.fixture\nsuccess index.ts\n' ) ;
336+ expectWriteSummary ( result . stdout , 2 , 2 ) ;
310337 expect ( result . stderr ) . toBe ( '' ) ;
311338 expect ( readProjectFile ( 'data.fixture' ) ) . toBe ( '{ "value": true }\n' ) ;
312339 expect ( readProjectFile ( 'index.ts' ) ) . toBe ( 'const value = true;\n' ) ;
@@ -343,10 +370,16 @@ test('returns exit code 2 for formatting errors', () => {
343370 expect ( result . stderr ) . toContain ( 'error index.ts: SyntaxError:' ) ;
344371} ) ;
345372
346- test ( 'succeeds when no files can be formatted ' , ( ) => {
347- const result = runFmt ( [ 'missing/**/*.ts' ] ) ;
373+ test ( 'reports when no files match ' , ( ) => {
374+ const writeResult = runFmt ( [ 'missing/**/*.ts' ] ) ;
348375
349- expect ( result . status ) . toBe ( 0 ) ;
350- expect ( result . stdout ) . toBe ( '' ) ;
351- expect ( result . stderr ) . toBe ( '' ) ;
376+ expect ( writeResult . status ) . toBe ( 0 ) ;
377+ expect ( writeResult . stdout ) . toBe ( 'info No files matched.\n' ) ;
378+ expect ( writeResult . stderr ) . toBe ( '' ) ;
379+
380+ const checkResult = runFmt ( [ '--check' , 'missing/**/*.ts' ] ) ;
381+
382+ expect ( checkResult . status ) . toBe ( 0 ) ;
383+ expect ( checkResult . stdout ) . toBe ( 'info No files matched.\n' ) ;
384+ expect ( checkResult . stderr ) . toBe ( '' ) ;
352385} ) ;
0 commit comments