@@ -5,7 +5,7 @@ import { CloneHandler } from '../../../../src/core/util/clone-handler';
55import { CloneContext } from '../../../../src/types/clone-context' ;
66import * as cliUtilities from '@contentstack/cli-utilities' ;
77import { rimraf } from 'rimraf' ;
8- import { readdirSync } from 'fs' ;
8+ import * as fs from 'fs' ;
99
1010describe ( 'StackCloneCommand' , ( ) => {
1111 let command : StackCloneCommand ;
@@ -108,7 +108,7 @@ describe('StackCloneCommand', () => {
108108
109109 describe ( 'removeContentDirIfNotEmptyBeforeClone' , ( ) => {
110110 it ( 'should remove directory when it exists and is not empty' , async ( ) => {
111- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ 'file1' , 'file2' ] ) ;
111+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ 'file1' , 'file2' ] as any ) ;
112112 const cleanUpStub = sandbox . stub ( command , 'cleanUp' ) . resolves ( ) ;
113113 const cloneContext : CloneContext = {
114114 command : 'test' ,
@@ -122,7 +122,7 @@ describe('StackCloneCommand', () => {
122122 } ) ;
123123
124124 it ( 'should not remove directory when it is empty' , async ( ) => {
125- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
125+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
126126 const cleanUpStub = sandbox . stub ( command , 'cleanUp' ) . resolves ( ) ;
127127 const cloneContext : CloneContext = {
128128 command : 'test' ,
@@ -138,7 +138,7 @@ describe('StackCloneCommand', () => {
138138 it ( 'should handle directory not existing' , async ( ) => {
139139 const error = new Error ( 'ENOENT' ) as any ;
140140 error . code = 'ENOENT' ;
141- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . throws ( error ) ;
141+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . rejects ( error ) ;
142142 const cleanUpStub = sandbox . stub ( command , 'cleanUp' ) . resolves ( ) ;
143143 const cloneContext : CloneContext = {
144144 command : 'test' ,
@@ -154,7 +154,7 @@ describe('StackCloneCommand', () => {
154154 it ( 'should log error for non-ENOENT error codes (covers line 305)' , async ( ) => {
155155 const error = new Error ( 'Permission denied' ) as any ;
156156 error . code = 'EACCES' ;
157- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . throws ( error ) ;
157+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . rejects ( error ) ;
158158 const logStub = {
159159 error : sandbox . stub ( ) ,
160160 warn : sandbox . stub ( ) ,
@@ -469,7 +469,7 @@ describe('StackCloneCommand', () => {
469469 configHandlerStub . withArgs ( 'email' ) . returns ( 'test@example.com' ) ;
470470 configHandlerStub . withArgs ( 'authtoken' ) . returns ( 'test-token' ) ;
471471 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
472- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
472+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
473473 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
474474 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
475475
@@ -494,7 +494,7 @@ describe('StackCloneCommand', () => {
494494 configHandlerStub . withArgs ( 'authtoken' ) . returns ( 'test-token' ) ;
495495 const readFileSyncStub = sandbox . stub ( require ( 'fs' ) , 'readFileSync' ) . returns ( '{"cloneType": "a"}' ) ;
496496 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
497- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
497+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
498498 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
499499 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
500500
@@ -526,7 +526,7 @@ describe('StackCloneCommand', () => {
526526 configHandlerStub . withArgs ( 'email' ) . returns ( 'test@example.com' ) ;
527527 configHandlerStub . withArgs ( 'authtoken' ) . returns ( 'test-token' ) ;
528528 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
529- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
529+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
530530 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
531531 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
532532
@@ -626,7 +626,7 @@ describe('StackCloneCommand', () => {
626626 } ;
627627 sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
628628 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
629- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
629+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
630630 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
631631 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
632632
@@ -657,7 +657,7 @@ describe('StackCloneCommand', () => {
657657 } ;
658658 sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
659659 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
660- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
660+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
661661 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
662662 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
663663
@@ -691,7 +691,7 @@ describe('StackCloneCommand', () => {
691691 } ;
692692 sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
693693 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
694- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
694+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
695695 const removeContentDirStub = sandbox . stub ( command , 'removeContentDirIfNotEmptyBeforeClone' ) . resolves ( ) ;
696696 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
697697 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
@@ -733,7 +733,7 @@ describe('StackCloneCommand', () => {
733733 } ;
734734 sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
735735 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
736- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
736+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
737737 const removeContentDirStub = sandbox . stub ( command , 'removeContentDirIfNotEmptyBeforeClone' ) . resolves ( ) ;
738738 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
739739 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
@@ -759,7 +759,7 @@ describe('StackCloneCommand', () => {
759759 configHandlerStub . withArgs ( 'authtoken' ) . returns ( 'test-token' ) ;
760760 configHandlerStub . withArgs ( 'authorisationType' ) . returns ( 'OAUTH' ) ;
761761 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
762- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
762+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
763763 const removeContentDirStub = sandbox . stub ( command , 'removeContentDirIfNotEmptyBeforeClone' ) . resolves ( ) ;
764764 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
765765 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
@@ -822,7 +822,7 @@ describe('StackCloneCommand', () => {
822822 } ;
823823 sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
824824 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
825- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
825+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
826826 const removeContentDirStub = sandbox . stub ( command , 'removeContentDirIfNotEmptyBeforeClone' ) . resolves ( ) ;
827827 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
828828 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . resolves ( ) ;
@@ -867,7 +867,7 @@ describe('StackCloneCommand', () => {
867867 sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
868868 const handleAndLogErrorStub = sandbox . stub ( cliUtilities , 'handleAndLogError' ) ;
869869 const managementSDKClientStub = sandbox . stub ( cliUtilities , 'managementSDKClient' ) . resolves ( { } as any ) ;
870- const readdirSyncStub = sandbox . stub ( require ( 'fs' ) , 'readdirSync' ) . returns ( [ ] ) ;
870+ const readdirStub = sandbox . stub ( fs . promises , 'readdir' as any ) . resolves ( [ ] as any ) ;
871871 const removeContentDirStub = sandbox . stub ( command , 'removeContentDirIfNotEmptyBeforeClone' ) . resolves ( ) ;
872872 const onStub = sandbox . stub ( process , 'on' ) . returns ( process ) ;
873873 const cloneHandlerExecuteStub = sandbox . stub ( CloneHandler . prototype , 'execute' ) . rejects ( new Error ( 'Execute error' ) ) ;
0 commit comments