import Fs from 'fs/promises' ; import Path from 'path' ; import { isEqualWith } from 'lodash' ; import type { Ecs , KibanaExecutionContext } from 'kibana/server' ; import type { RetryService } from '../../../test/common/services/retry' ; export const logFilePath = Path . resolve ( __dirname , './kibana.log' ) ; export const ANY = Symbol ( 'any' ) ; export function isExecutionContextLog ( record , executionContext ) { if ( ! record ) return false ; try { const object = JSON . parse ( record ) ; return isEqualWith ( object , executionContext , function customizer ( obj1 , obj2 ) { if ( obj2 === ANY ) return true ; } ) ; } catch ( e ) { return false ; } } const endOfLine = /(?<=})\s*\n/ ; export async function assertLogContains ( { description , predicate , retry , } ) { await retry . waitFor ( description , async ( ) => { const logsStr = await Fs . readFile ( logFilePath , 'utf-8' ) ; const normalizedRecords = logsStr . split ( endOfLine ) . filter ( Boolean ) . map ( ( s ) => JSON . parse ( s ) ) ; return normalizedRecords . some ( predicate ) ; } ) ; }