import fs from 'fs' ; import path from 'path' ; const ignoredContents = [ 'node_modules' ] ; const ignoreContent = ( name ) => ! ignoredContents . includes ( name ) ; export const dirEqual = ( expected , actual ) => { const actualStat = fs . statSync ( actual ) ; const expectedStat = fs . statSync ( expected ) ; if ( expectedStat . isDirectory ( ) ) { expect ( actualStat . isDirectory ( ) ) . toBe ( true ) ; const expectedContent = fs . readdirSync ( expected ) . filter ( ignoreContent ) ; const actualContent = fs . readdirSync ( actual ) . filter ( ignoreContent ) ; expect ( actualContent ) . toStrictEqual ( expectedContent ) ; expectedContent . forEach ( ( expectedChildren , i ) => dirEqual ( path . join ( expected , expectedChildren ) , path . join ( actual , actualContent [ i ] ) ) ) ; } else if ( expectedStat . isFile ( ) ) { expect ( actualStat . isFile ( ) ) . toBe ( true ) ; const expectedOutput = fs . readFileSync ( expected , 'utf-8' ) ; const actualOutput = fs . readFileSync ( actual , 'utf-8' ) ; expect ( ( actualOutput || '' ) . trim ( ) ) . toEqual ( expectedOutput . trim ( ) ) ; } else { console . log ( `Unexpected type of "${ expected }", it's not directory or file.` ) ; } } ;