import fs from 'fs' ; export interface UnsupportedTypeLog { header : string ; created : string ; usedBy : string ; } export const getLogsByCreateMockFileName = async ( fileName ) => { const logErrorFile = await ensureGetLogFileContent ( ) ; const logs = [ ] ; const lines = logErrorFile . split ( '\n' ) . filter ( ( line ) => ! ! line ) ; for ( let i = 0 ; i < lines . length ; i += 3 ) { logs . push ( { header : lines [ i ] , created : lines [ i + 1 ] , usedBy : lines [ i + 2 ] , } ) ; } return logs . filter ( ( log ) => log . created . indexOf ( fileName ) > - 1 ) ; } ; /**
  On Windows the log file is empty for the first test, if that happens we wait 10 ms to fetch it again.
  After few tests 10 ms is enough time. It's still a random amount of time but luckily this is useful only for
  local development since build servers are usually Unix.
 */ async function ensureGetLogFileContent ( ) { return await fetchAgainIfEmpty ( './tsAutoMock.log' ) ; } async function fetchAgainIfEmpty ( filepath ) { let logErrorFile = fs . readFileSync ( filepath , 'utf-8' ) ; if ( logErrorFile === '' ) { await waitSomeAmountOfTime ( ) ; logErrorFile = fs . readFileSync ( filepath , 'utf-8' ) ; } return logErrorFile ; } async function waitSomeAmountOfTime ( ) { await new Promise ( ( r ) => setTimeout ( ( ) => r ( ) , 10 ) ) ; }