import fs from "fs" ; import path from "path" ; import uuid from "uuid/v4" ; import { disableVerboseLogging , enableVerboseLogging , logger } from "." ; import { CLI_LOG_FILENAME } from "../lib/constants" ; const logFile = path . join ( process . cwd ( ) , CLI_LOG_FILENAME ) ; test ( "A new info log gets added to logs" , ( ) => { const randomString = uuid ( ) ; logger . info ( randomString , ( ) => { expect ( fs . readFileSync ( logFile , "utf8" ) ) . toMatch ( new RegExp ( `.+${ randomString }.+` , "s" ) ) ; } ) ; } ) ; test ( "A new error log gets added to logs" , ( ) => { const randomString = uuid ( ) ; logger . error ( randomString , ( ) => { expect ( fs . readFileSync ( logFile , "utf8" ) ) . toMatch ( new RegExp ( `.+${ randomString }.+` , "s" ) ) ; } ) ; } ) ; test ( "Set verbose logging" , ( ) => { const randomString = uuid ( ) ; logger . debug ( randomString , ( ) => { expect ( fs . readFileSync ( logFile , "utf8" ) ) . not . toMatch ( new RegExp ( `.+${ randomString }.+` , "s" ) ) ; } ) ; enableVerboseLogging ( ) ; logger . debug ( randomString , ( ) => { expect ( fs . readFileSync ( logFile , "utf8" ) ) . toMatch ( new RegExp ( `.+${ randomString }.+` , "s" ) ) ; } ) ; disableVerboseLogging ( ) ; const newRandomString = uuid ( ) ; logger . debug ( newRandomString , ( ) => { expect ( fs . readFileSync ( logFile , "utf8" ) ) . not . toMatch ( new RegExp ( `.+${ newRandomString }.+` , "s" ) ) ; } ) ; } ) ;