@@ -12,21 +12,21 @@ function createMockFs(
1212 return {
1313 written,
1414 dirs,
15- readFileSync ( path : string ) {
15+ async readFile ( path : string ) {
1616 const content = store . get ( toUnixPath ( path ) ) ;
1717 if ( content == null ) {
1818 throw new Error ( `ENOENT: no such file or directory, open '${ path } '` ) ;
1919 }
2020 return content ;
2121 } ,
22- writeFileSync ( path : string , content : string ) {
22+ async writeFile ( path : string , content : string ) {
2323 store . set ( toUnixPath ( path ) , content ) ;
2424 written . set ( toUnixPath ( path ) , content ) ;
2525 } ,
26- existsSync ( path : string ) {
26+ async exists ( path : string ) {
2727 return store . has ( toUnixPath ( path ) ) ;
2828 } ,
29- mkdirSync ( _path : string , _options : { recursive : boolean } ) {
29+ async mkdir ( _path : string , _options : { recursive : boolean } ) {
3030 // eslint-disable-next-line functional/immutable-data
3131 dirs . push ( toUnixPath ( _path ) ) ;
3232 } ,
@@ -39,70 +39,70 @@ describe('createTree', () => {
3939 } ) ;
4040
4141 describe ( 'exists' , ( ) => {
42- it ( 'should return false for non-existent files' , ( ) => {
43- expect (
42+ it ( 'should return false for non-existent files' , async ( ) => {
43+ await expect (
4444 createTree ( '/project' , createMockFs ( ) ) . exists ( 'missing.ts' ) ,
45- ) . toBeFalse ( ) ;
45+ ) . resolves . toBeFalse ( ) ;
4646 } ) ;
4747
48- it ( 'should return true for files on disk' , ( ) => {
49- expect (
48+ it ( 'should return true for files on disk' , async ( ) => {
49+ await expect (
5050 createTree (
5151 '/project' ,
5252 createMockFs ( { '/project/existing.ts' : 'content' } ) ,
5353 ) . exists ( 'existing.ts' ) ,
54- ) . toBeTrue ( ) ;
54+ ) . resolves . toBeTrue ( ) ;
5555 } ) ;
5656
57- it ( 'should return true for files written to the tree' , ( ) => {
57+ it ( 'should return true for files written to the tree' , async ( ) => {
5858 const tree = createTree ( '/project' , createMockFs ( ) ) ;
59- tree . write ( 'new.ts' , 'content' ) ;
60- expect ( tree . exists ( 'new.ts' ) ) . toBeTrue ( ) ;
59+ await tree . write ( 'new.ts' , 'content' ) ;
60+ await expect ( tree . exists ( 'new.ts' ) ) . resolves . toBeTrue ( ) ;
6161 } ) ;
6262 } ) ;
6363
6464 describe ( 'read' , ( ) => {
65- it ( 'should return null for non-existent files' , ( ) => {
66- expect (
65+ it ( 'should return null for non-existent files' , async ( ) => {
66+ await expect (
6767 createTree ( '/project' , createMockFs ( ) ) . read ( 'missing.ts' ) ,
68- ) . toBeNull ( ) ;
68+ ) . resolves . toBeNull ( ) ;
6969 } ) ;
7070
71- it ( 'should read files from disk' , ( ) => {
72- expect (
71+ it ( 'should read files from disk' , async ( ) => {
72+ await expect (
7373 createTree (
7474 '/project' ,
7575 createMockFs ( { '/project/existing.ts' : 'disk content' } ) ,
7676 ) . read ( 'existing.ts' ) ,
77- ) . toBe ( 'disk content' ) ;
77+ ) . resolves . toBe ( 'disk content' ) ;
7878 } ) ;
7979
80- it ( 'should return pending content over disk content' , ( ) => {
80+ it ( 'should return pending content over disk content' , async ( ) => {
8181 const tree = createTree (
8282 '/project' ,
8383 createMockFs ( { '/project/file.ts' : 'old' } ) ,
8484 ) ;
85- tree . write ( 'file.ts' , 'new' ) ;
86- expect ( tree . read ( 'file.ts' ) ) . toBe ( 'new' ) ;
85+ await tree . write ( 'file.ts' , 'new' ) ;
86+ await expect ( tree . read ( 'file.ts' ) ) . resolves . toBe ( 'new' ) ;
8787 } ) ;
8888 } ) ;
8989
9090 describe ( 'write' , ( ) => {
91- it ( 'should mark new files as CREATE' , ( ) => {
91+ it ( 'should mark new files as CREATE' , async ( ) => {
9292 const tree = createTree ( '/project' , createMockFs ( ) ) ;
93- tree . write ( 'new.ts' , 'content' ) ;
93+ await tree . write ( 'new.ts' , 'content' ) ;
9494
9595 expect ( tree . listChanges ( ) ) . toStrictEqual ( [
9696 { path : 'new.ts' , type : 'CREATE' , content : 'content' } ,
9797 ] ) ;
9898 } ) ;
9999
100- it ( 'should mark existing files as UPDATE' , ( ) => {
100+ it ( 'should mark existing files as UPDATE' , async ( ) => {
101101 const tree = createTree (
102102 '/project' ,
103103 createMockFs ( { '/project/existing.ts' : 'old' } ) ,
104104 ) ;
105- tree . write ( 'existing.ts' , 'new' ) ;
105+ await tree . write ( 'existing.ts' , 'new' ) ;
106106
107107 expect ( tree . listChanges ( ) ) . toStrictEqual ( [
108108 { path : 'existing.ts' , type : 'UPDATE' , content : 'new' } ,
@@ -117,13 +117,13 @@ describe('createTree', () => {
117117 ) . toStrictEqual ( [ ] ) ;
118118 } ) ;
119119
120- it ( 'should return all pending changes' , ( ) => {
120+ it ( 'should return all pending changes' , async ( ) => {
121121 const tree = createTree (
122122 '/project' ,
123123 createMockFs ( { '/project/existing.ts' : 'old' } ) ,
124124 ) ;
125- tree . write ( 'new.ts' , 'created' ) ;
126- tree . write ( 'existing.ts' , 'updated' ) ;
125+ await tree . write ( 'new.ts' , 'created' ) ;
126+ await tree . write ( 'existing.ts' , 'updated' ) ;
127127
128128 expect ( tree . listChanges ( ) ) . toHaveLength ( 2 ) ;
129129 expect ( tree . listChanges ( ) ) . toContainEqual ( {
@@ -143,7 +143,7 @@ describe('createTree', () => {
143143 it ( 'should write all pending files to the fs' , async ( ) => {
144144 const fs = createMockFs ( ) ;
145145 const tree = createTree ( '/project' , fs ) ;
146- tree . write ( 'src/config.ts' , 'export default {};' ) ;
146+ await tree . write ( 'src/config.ts' , 'export default {};' ) ;
147147
148148 await tree . flush ( ) ;
149149
@@ -155,7 +155,7 @@ describe('createTree', () => {
155155 it ( 'should create parent directories' , async ( ) => {
156156 const fs = createMockFs ( ) ;
157157 const tree = createTree ( '/project' , fs ) ;
158- tree . write ( 'src/deep/config.ts' , 'content' ) ;
158+ await tree . write ( 'src/deep/config.ts' , 'content' ) ;
159159
160160 await tree . flush ( ) ;
161161
@@ -164,7 +164,7 @@ describe('createTree', () => {
164164
165165 it ( 'should clear pending changes after flush' , async ( ) => {
166166 const tree = createTree ( '/project' , createMockFs ( ) ) ;
167- tree . write ( 'file.ts' , 'content' ) ;
167+ await tree . write ( 'file.ts' , 'content' ) ;
168168
169169 await tree . flush ( ) ;
170170
0 commit comments