@@ -311,7 +311,7 @@ test('does not cache formatting errors', async () => {
311311 } ) ;
312312} ) ;
313313
314- test ( 'write persists clean results for misses and hits' , async ( ) => {
314+ test ( 'write persists checked input results for misses and hits' , async ( ) => {
315315 await withTempProject ( async ( rootPath ) => {
316316 const cleanPath = path . join ( rootPath , 'clean.ts' ) ;
317317 const dirtyPath = path . join ( rootPath , 'dirty.ts' ) ;
@@ -333,9 +333,9 @@ test('write persists clean results for misses and hits', async () => {
333333 'clean' ,
334334 ] ) ;
335335 expect ( store . get ( 'dirty.ts' ) ) . toEqual ( [
336- createCacheHash ( readFileSync ( dirtyPath ) ) ,
336+ createCacheHash ( 'const dirty=1' ) ,
337337 expect . any ( String ) ,
338- 'clean ' ,
338+ 'dirty ' ,
339339 ] ) ;
340340
341341 const timestamps = files . map ( ( file ) => statSync ( file . path ) . mtimeMs ) ;
@@ -350,7 +350,7 @@ test('write persists clean results for misses and hits', async () => {
350350 } ) ;
351351} ) ;
352352
353- test ( 'write converts a dirty entry to clean ' , async ( ) => {
353+ test ( 'write keeps a dirty entry until the output is checked ' , async ( ) => {
354354 await withTempProject ( async ( rootPath ) => {
355355 const filePath = path . join ( rootPath , 'index.ts' ) ;
356356 const cache = createFmtCacheContext ( rootPath ) ;
@@ -367,13 +367,39 @@ test('write converts a dirty entry to clean', async () => {
367367
368368 const store = await loadFmtCacheStore ( cache . filePath , cacheNamespace ) ;
369369 expect ( store . get ( 'index.ts' ) ) . toEqual ( [
370- createCacheHash ( readFileSync ( filePath ) ) ,
370+ createCacheHash ( 'const value=1' ) ,
371371 expect . any ( String ) ,
372- 'clean ' ,
372+ 'dirty ' ,
373373 ] ) ;
374374 await expect ( run ( [ file ] , 'check' , cache ) ) . resolves . toMatchObject ( {
375375 exitCode : 0 ,
376376 files : [ ] ,
377377 } ) ;
378378 } ) ;
379379} ) ;
380+
381+ test ( 'cached check matches uncached check after writing non-idempotent output' , async ( ) => {
382+ await withTempProject ( async ( rootPath ) => {
383+ // Preserve these line breaks: this input needs two passes in Prettier 3.9.6.
384+ const filePath = writeProjectFile (
385+ rootPath ,
386+ 'example.ts' ,
387+ `const fetch = rs.fn<typeof globalThis.fetch>().mockImplementation(() => Promise.resolve(
388+ new Response('cached pixels', { headers: { 'content-type': 'image/webp' } }),
389+ ));
390+ ` ,
391+ ) ;
392+ const files = [
393+ createFmtRequest ( filePath , {
394+ parser : 'typescript' ,
395+ singleQuote : true ,
396+ trailingComma : 'all' ,
397+ } ) ,
398+ ] ;
399+ const cache = createFmtCacheContext ( rootPath ) ;
400+
401+ await run ( files , 'write' , cache ) ;
402+ const uncached = await runFmtFiles ( { files, mode : 'check' } ) ;
403+ await expect ( run ( files , 'check' , cache ) ) . resolves . toEqual ( uncached ) ;
404+ } ) ;
405+ } ) ;
0 commit comments