@@ -59,20 +59,20 @@ describe("SyncClient", () => {
5959 expect ( result . uploadedFiles ) . toHaveLength ( 3 ) ;
6060 expect ( result . totalFilesUploaded ) . toBe ( 3 ) ;
6161 expect ( result . uploadedFiles ) . toContain (
62- path . join ( destinationPath , "file1.txt" )
62+ path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" )
6363 ) ;
6464 expect ( result . uploadedFiles ) . toContain (
65- path . join ( destinationPath , "file2.txt" )
65+ path . join ( destinationPath , "file2.txt" ) . replace ( / \\ / g , "/" )
6666 ) ;
6767 expect ( result . uploadedFiles ) . toContain (
68- path . join ( destinationPath , "subdir/file3.txt" )
68+ path . join ( destinationPath , "subdir/file3.txt" ) . replace ( / \\ / g , "/" )
6969 ) ;
7070
7171 // Verify uploadFile was called for each file with correct destination paths
7272 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledTimes ( 3 ) ;
7373 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledWith (
7474 path . join ( tempDir , "file1.txt" ) ,
75- path . join ( destinationPath , "file1.txt" )
75+ path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" )
7676 ) ;
7777 expect ( mockGcpClient . listContent ) . toHaveBeenCalledTimes ( 1 ) ;
7878 expect ( mockGcpClient . listContent ) . toHaveBeenCalledWith (
@@ -83,15 +83,15 @@ describe("SyncClient", () => {
8383
8484 it ( "should skip existing files with same size" , async ( ) => {
8585 // Mock existing files in bucket
86- const file1Stats = await fs . promises . stat ( path . join ( tempDir , "file1.txt" ) ) ;
86+ const file1Stats = await fs . promises . stat ( path . join ( tempDir , "file1.txt" ) . replace ( / \\ / g , "/" ) ) ;
8787 const file3Stats = await fs . promises . stat (
88- path . join ( tempDir , "subdir" , "file3.txt" )
88+ path . join ( tempDir , "subdir" , "file3.txt" ) . replace ( / \\ / g , "/" )
8989 ) ;
9090
9191 mockGcpClient . listContent . mockResolvedValueOnce ( [
92- { name : path . join ( destinationPath , "file1.txt" ) , size : file1Stats . size } ,
92+ { name : path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" ) , size : file1Stats . size } ,
9393 {
94- name : path . join ( destinationPath , "subdir/file3.txt" ) ,
94+ name : path . join ( destinationPath , "subdir/file3.txt" ) . replace ( / \\ / g , "/" ) ,
9595 size : file3Stats . size ,
9696 } ,
9797 ] ) ;
@@ -103,14 +103,14 @@ describe("SyncClient", () => {
103103 expect ( result . uploadedFiles ) . toHaveLength ( 1 ) ;
104104 expect ( result . totalFilesUploaded ) . toBe ( 1 ) ;
105105 expect ( result . uploadedFiles ) . toContain (
106- path . join ( destinationPath , "file2.txt" )
106+ path . join ( destinationPath , "file2.txt" ) . replace ( / \\ / g , "/" )
107107 ) ;
108108
109109 // Verify uploadFile was called only once with correct destination path
110110 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledTimes ( 1 ) ;
111111 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledWith (
112112 path . join ( tempDir , "file2.txt" ) ,
113- path . join ( destinationPath , "file2.txt" )
113+ path . join ( destinationPath , "file2.txt" ) . replace ( / \\ / g , "/" )
114114 ) ;
115115 } ) ;
116116
@@ -129,11 +129,11 @@ describe("SyncClient", () => {
129129
130130 // Verify file1.txt was uploaded again due to size difference
131131 expect ( result . uploadedFiles ) . toContain (
132- path . join ( destinationPath , "file1.txt" )
132+ path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" )
133133 ) ;
134134 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledWith (
135135 path . join ( tempDir , "file1.txt" ) ,
136- path . join ( destinationPath , "file1.txt" )
136+ path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" )
137137 ) ;
138138 } ) ;
139139
@@ -157,23 +157,23 @@ describe("SyncClient", () => {
157157 // Verify all files are uploaded to the correct destination path
158158 expect ( result . uploadedFiles ) . toHaveLength ( 3 ) ;
159159 expect ( result . uploadedFiles ) . toEqual ( [
160- path . join ( destinationPath , "file1.txt" ) ,
161- path . join ( destinationPath , "file2.txt" ) ,
162- path . join ( destinationPath , "subdir/file3.txt" ) ,
160+ path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" ) ,
161+ path . join ( destinationPath , "file2.txt" ) . replace ( / \\ / g , "/" ) ,
162+ path . join ( destinationPath , "subdir/file3.txt" ) . replace ( / \\ / g , "/" ) ,
163163 ] ) ;
164164
165165 // Verify uploadFile was called with correct destination paths
166166 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledWith (
167167 path . join ( tempDir , "file1.txt" ) ,
168- path . join ( destinationPath , "file1.txt" )
168+ path . join ( destinationPath , "file1.txt" ) . replace ( / \\ / g , "/" )
169169 ) ;
170170 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledWith (
171171 path . join ( tempDir , "file2.txt" ) ,
172- path . join ( destinationPath , "file2.txt" )
172+ path . join ( destinationPath , "file2.txt" ) . replace ( / \\ / g , "/" )
173173 ) ;
174174 expect ( mockGcpClient . uploadFile ) . toHaveBeenCalledWith (
175175 path . join ( tempDir , "subdir/file3.txt" ) ,
176- path . join ( destinationPath , "subdir/file3.txt" )
176+ path . join ( destinationPath , "subdir/file3.txt" ) . replace ( / \\ / g , "/" )
177177 ) ;
178178
179179 // Verify listContent was called with the correct destination path
@@ -182,4 +182,26 @@ describe("SyncClient", () => {
182182 destinationPath
183183 ) ;
184184 } ) ;
185+
186+ it ( "should return paths with forward slashes even on Windows" , async ( ) => {
187+ // Create a nested directory structure with backslashes
188+ const nestedDir = path . join ( tempDir , "nested" , "deep" , "dir" ) ;
189+ await fs . promises . mkdir ( nestedDir , { recursive : true } ) ;
190+ await fs . promises . writeFile (
191+ path . join ( nestedDir , "test.txt" ) ,
192+ "test content"
193+ ) ;
194+
195+ // Get the files using listFiles
196+ const files = await ( syncClient as any ) . listFiles ( ) ;
197+
198+ // Find the nested file path
199+ const nestedFilePath = files . find ( ( [ _ , path ] : [ string , string ] ) => path . includes ( "test.txt" ) ) ?. [ 1 ] ;
200+
201+ // Verify the nested path uses forward slashes
202+ expect ( nestedFilePath ) . not . toContain ( "\\" ) ;
203+ expect ( nestedFilePath ) . toContain ( "/" ) ;
204+ expect ( nestedFilePath ) . toBe ( "nested/deep/dir/test.txt" ) ;
205+ } ) ;
206+
185207} ) ;
0 commit comments