11import { describe , it , expect , beforeEach , afterEach } from 'vitest'
22import { readJsonSafe , writeJsonAtomic , withFileLock } from './atomic-json'
33import { join } from 'node:path'
4- import { mkdtemp , rm } from 'node:fs/promises'
4+ import { mkdtemp , rm , writeFile , readFile } from 'node:fs/promises'
55import { tmpdir } from 'node:os'
66
77describe ( 'atomic-json' , ( ) => {
@@ -24,7 +24,7 @@ describe('atomic-json', () => {
2424
2525 it ( 'returns fallback when file contains invalid JSON and logs a warning' , async ( ) => {
2626 const filePath = join ( tmpDir , 'invalid.json' )
27- await Bun . write ( filePath , '{ invalid json }' )
27+ await writeFile ( filePath , '{ invalid json }' , 'utf8 ')
2828 const fallback = { foo : 'bar' }
2929 const result = await readJsonSafe ( filePath , fallback )
3030 expect ( result ) . toEqual ( fallback )
@@ -33,7 +33,7 @@ describe('atomic-json', () => {
3333 it ( 'returns parsed value when file contains valid JSON' , async ( ) => {
3434 const filePath = join ( tmpDir , 'valid.json' )
3535 const data = { foo : 'bar' , nested : { value : 42 } }
36- await Bun . write ( filePath , JSON . stringify ( data ) )
36+ await writeFile ( filePath , JSON . stringify ( data ) , 'utf8' )
3737 const result = await readJsonSafe ( filePath , { fallback : true } )
3838 expect ( result ) . toEqual ( data )
3939 } )
@@ -44,7 +44,7 @@ describe('atomic-json', () => {
4444 const filePath = join ( tmpDir , 'output.json' )
4545 const data = { test : 'value' , number : 123 }
4646 await writeJsonAtomic ( filePath , data )
47- const content = await Bun . file ( filePath ) . text ( )
47+ const content = await readFile ( filePath , 'utf8' )
4848 const parsed = JSON . parse ( content )
4949 expect ( parsed ) . toEqual ( data )
5050 } )
0 commit comments