@@ -27,7 +27,7 @@ describe('Browser main tests', function () {
2727 expect ( Filer . fs . name ) . to . equal ( 'local' ) ;
2828 } ) ;
2929
30- it ( 'Should load Phoenix fs in browser' , async function ( ) {
30+ it ( 'Should load clean Phoenix fs in browser' , async function ( ) {
3131 expect ( fs ) . to . exist ;
3232 expect ( fs . name ) . to . equal ( 'phoenixFS' ) ;
3333 // setup test folders
@@ -56,7 +56,7 @@ describe('Browser main tests', function () {
5656 cleanSuccess = true ;
5757 } ) ;
5858 await waitForTrue ( ( ) => { return cleanSuccess ; } , 10000 ) ;
59- } ) ;
59+ } , 10000 ) ;
6060
6161 it ( 'Should phoenix native write in browser' , async function ( ) {
6262 let writeSuccess = false ;
@@ -184,4 +184,139 @@ describe('Browser main tests', function () {
184184 await waitForTrue ( ( ) => { return failed ; } , 1000 ) ;
185185 expect ( failed ) . to . be . true ;
186186 } ) ;
187+
188+ function _createFolder ( path ) {
189+ return new Promise ( ( resolve , reject ) => {
190+ fs . mkdir ( path , 777 , ( err ) => {
191+ if ( err ) {
192+ reject ( err ) ;
193+ } else {
194+ resolve ( ) ;
195+ }
196+ } ) ;
197+ } ) ;
198+ }
199+ function _createFile ( path ) {
200+ return new Promise ( ( resolve , reject ) => {
201+ fs . writeFile ( path , 'hello World' , 'utf8' , ( err ) => {
202+ if ( ! err ) {
203+ resolve ( ) ;
204+ } else {
205+ reject ( ) ;
206+ }
207+ } ) ;
208+ } ) ;
209+ }
210+
211+ function _shouldExist ( path ) {
212+ return new Promise ( ( resolve ) => {
213+ fs . stat ( path , ( err ) => {
214+ if ( err ) {
215+ resolve ( false ) ;
216+ } else {
217+ resolve ( true ) ;
218+ }
219+ } ) ;
220+ } ) ;
221+ }
222+
223+ async function _createTestFolderInBasePath ( path , folderName ) {
224+ await _createFolder ( `${ path } /${ folderName } ` ) ;
225+ await _createFile ( `${ path } /${ folderName } /a.txt` ) ;
226+ await _createFile ( `${ path } /${ folderName } /b.txt` ) ;
227+ await _createFolder ( `${ path } /${ folderName } /y` ) ;
228+ await _createFolder ( `${ path } /${ folderName } /z` ) ;
229+ await _createFile ( `${ path } /${ folderName } /y/c.txt` ) ;
230+ }
231+
232+ async function _verifyCopyFolder ( srcPath , dstPath , expectedPath ) {
233+ let success = false ;
234+ fs . copy ( srcPath , dstPath , ( err ) => {
235+ if ( ! err ) {
236+ success = true ;
237+ }
238+ } ) ;
239+ await waitForTrue ( ( ) => { return success ; } , 1000 ) ;
240+ expect ( success ) . to . be . true ;
241+ expectedPath = expectedPath || dstPath ;
242+ expect ( await _shouldExist ( `${ expectedPath } /a.txt` ) ) . to . be . true ;
243+ expect ( await _shouldExist ( `${ expectedPath } /y` ) ) . to . be . true ;
244+ expect ( await _shouldExist ( `${ expectedPath } /y/c.txt` ) ) . to . be . true ;
245+ }
246+
247+ it ( 'Should phoenix copy fail if dst is a subpath of src' , async function ( ) {
248+ let errored = false ;
249+ fs . copy ( '/a' , '/a/b' , ( err ) => {
250+ if ( err ) {
251+ errored = true ;
252+ }
253+ } ) ;
254+ await waitForTrue ( ( ) => { return errored ; } , 1000 ) ;
255+ expect ( errored ) . to . be . true ;
256+ } ) ;
257+
258+ it ( 'Should phoenix copy folder from mount to filer path' , async function ( ) {
259+ await _createTestFolderInBasePath ( window . mountTestPath , 'testDir2' ) ;
260+ let srcPath = `${ window . mountTestPath } /testDir2` ;
261+ let dstPath = `${ window . virtualTestPath } /testDir2` ;
262+ await _verifyCopyFolder ( srcPath , dstPath ) ;
263+ } ) ;
264+
265+ it ( 'Should phoenix copy overwrite folder from mount to filer path if already exist' , async function ( ) {
266+ await _createTestFolderInBasePath ( window . mountTestPath , 'testDir3' ) ;
267+ let srcPath = `${ window . mountTestPath } /testDir3` ;
268+ let dstPath = `${ window . virtualTestPath } /testDir3` ;
269+ let expectedPath = `${ window . virtualTestPath } /testDir3/testDir3` ;
270+ await _createFolder ( dstPath ) ;
271+ await _verifyCopyFolder ( srcPath , dstPath , expectedPath ) ;
272+ } ) ;
273+
274+ it ( 'Should phoenix copy folder from filer to mount path' , async function ( ) {
275+ await _createTestFolderInBasePath ( window . virtualTestPath , 'testDir4' ) ;
276+ let srcPath = `${ window . virtualTestPath } /testDir4` ;
277+ let dstPath = `${ window . mountTestPath } /testDir4` ;
278+ await _verifyCopyFolder ( srcPath , dstPath ) ;
279+ } ) ;
280+
281+ it ( 'Should phoenix copy overwrite folder from filer to mount path if already exist' , async function ( ) {
282+ await _createTestFolderInBasePath ( window . virtualTestPath , 'testDir5' ) ;
283+ let srcPath = `${ window . virtualTestPath } /testDir5` ;
284+ let dstPath = `${ window . mountTestPath } /testDir5` ;
285+ let expectedPath = `${ window . mountTestPath } /testDir5/testDir5` ;
286+ await _createFolder ( dstPath ) ;
287+ await _verifyCopyFolder ( srcPath , dstPath , expectedPath ) ;
288+ } ) ;
289+
290+ it ( 'Should phoenix copy folder from filer to filer path' , async function ( ) {
291+ await _createTestFolderInBasePath ( window . virtualTestPath , 'testDir6' ) ;
292+ let srcPath = `${ window . virtualTestPath } /testDir6` ;
293+ let dstPath = `${ window . virtualTestPath } /testDir6.5` ;
294+ await _verifyCopyFolder ( srcPath , dstPath ) ;
295+ } ) ;
296+
297+ it ( 'Should phoenix copy overwrite folder from filer to filer path if already exist' , async function ( ) {
298+ await _createTestFolderInBasePath ( window . virtualTestPath , 'testDir7' ) ;
299+ let srcPath = `${ window . virtualTestPath } /testDir7` ;
300+ let dstPath = `${ window . virtualTestPath } /testDir7.5` ;
301+ let expectedPath = `${ window . virtualTestPath } /testDir7.5/testDir7` ;
302+ await _createFolder ( dstPath ) ;
303+ await _verifyCopyFolder ( srcPath , dstPath , expectedPath ) ;
304+ } ) ;
305+
306+ it ( 'Should phoenix copy folder from mount to mount path' , async function ( ) {
307+ await _createTestFolderInBasePath ( window . mountTestPath , 'testDir8' ) ;
308+ let srcPath = `${ window . mountTestPath } /testDir8` ;
309+ let dstPath = `${ window . mountTestPath } /testDir8.5` ;
310+ await _verifyCopyFolder ( srcPath , dstPath ) ;
311+ } ) ;
312+
313+ it ( 'Should phoenix copy as sub-folder from mount to mount if dest path already exist' , async function ( ) {
314+ await _createTestFolderInBasePath ( window . mountTestPath , 'testDir9' ) ;
315+ let srcPath = `${ window . mountTestPath } /testDir9` ;
316+ let dstPath = `${ window . mountTestPath } /testDir9.5` ;
317+ let expectedPath = `${ window . mountTestPath } /testDir9.5/testDir9` ;
318+ await _createFolder ( dstPath ) ;
319+ await _verifyCopyFolder ( srcPath , dstPath , expectedPath ) ;
320+ } ) ;
321+
187322} ) ;
0 commit comments