@@ -25,6 +25,27 @@ import { ExportResultArchiveStructure } from '../../shared/utilities/download'
2525import { JDKVersion , TransformationType } from '../../codewhisperer'
2626
2727describe ( 'Transformation History Handler' , function ( ) {
28+ function setupFileSystemMocks ( ) {
29+ const createdFiles = new Map < string , string > ( )
30+ const createdDirs = new Set < string > ( )
31+
32+ // Mock file operations to track what gets created
33+ sinon . stub ( fs , 'mkdir' ) . callsFake ( async ( dirPath : any ) => {
34+ createdDirs . add ( dirPath . toString ( ) )
35+ } )
36+ sinon . stub ( fs , 'copy' ) . callsFake ( async ( src : any , dest : any ) => {
37+ createdFiles . set ( dest . toString ( ) , `copied from ${ src . toString ( ) } ` )
38+ } )
39+ sinon . stub ( fs , 'writeFile' ) . callsFake ( async ( filePath : any , content : any ) => {
40+ createdFiles . set ( filePath . toString ( ) , content . toString ( ) )
41+ } )
42+ sinon . stub ( fs , 'delete' ) . callsFake ( async ( filePath : any ) => {
43+ createdFiles . delete ( filePath . toString ( ) )
44+ } )
45+
46+ return { createdFiles, createdDirs }
47+ }
48+
2849 afterEach ( function ( ) {
2950 sinon . restore ( )
3051 } )
@@ -157,22 +178,9 @@ describe('Transformation History Handler', function () {
157178 }
158179
159180 beforeEach ( function ( ) {
160- createdFiles = new Map ( )
161- createdDirs = new Set ( )
162-
163- // Mock file operations to track what gets created
164- sinon . stub ( fs , 'mkdir' ) . callsFake ( async ( dirPath : any ) => {
165- createdDirs . add ( dirPath . toString ( ) )
166- } )
167- sinon . stub ( fs , 'copy' ) . callsFake ( async ( src : any , dest : any ) => {
168- createdFiles . set ( dest . toString ( ) , `copied from ${ src . toString ( ) } ` )
169- } )
170- sinon . stub ( fs , 'writeFile' ) . callsFake ( async ( filePath : any , content : any ) => {
171- createdFiles . set ( filePath . toString ( ) , content . toString ( ) )
172- } )
173- sinon . stub ( fs , 'delete' ) . callsFake ( async ( filePath : any ) => {
174- createdFiles . delete ( filePath . toString ( ) )
175- } )
181+ const mocks = setupFileSystemMocks ( )
182+ createdFiles = mocks . createdFiles
183+ createdDirs = mocks . createdDirs
176184 } )
177185
178186 it ( 'Creates job history directory and metadata files' , async function ( ) {
@@ -229,16 +237,9 @@ describe('Transformation History Handler', function () {
229237 let createdDirs : Set < string >
230238
231239 beforeEach ( function ( ) {
232- createdFiles = new Map ( )
233- createdDirs = new Set ( )
234-
235- // Mock file operations to track what gets created
236- sinon . stub ( fs , 'mkdir' ) . callsFake ( async ( dirPath : any ) => {
237- createdDirs . add ( dirPath . toString ( ) )
238- } )
239- sinon . stub ( fs , 'copy' ) . callsFake ( async ( src : any , dest : any ) => {
240- createdFiles . set ( dest . toString ( ) , `copied from ${ src . toString ( ) } ` )
241- } )
240+ const mocks = setupFileSystemMocks ( )
241+ createdFiles = mocks . createdFiles
242+ createdDirs = mocks . createdDirs
242243 } )
243244
244245 it ( 'Copies diff patch and summary files to destination' , async function ( ) {
0 commit comments