import { Readable } from 'stream' ; import { createConcatStream , createPromiseFromStreams } from '@kbn/utils' ; async function readStreamToCompletion ( stream ) { return ( await ( createPromiseFromStreams ( [ stream , createConcatStream ( [ ] ) ] ) as unknown ) ) as any [ ] ; } export const createExportSavedObjectsToStreamMock = ( ) => { return jest . fn ( ) . mockResolvedValue ( new Readable ( { objectMode : true , read ( ) { this . push ( null ) ; } , } ) ) ; } ; export const createImportSavedObjectsFromStreamMock = ( ) => { return jest . fn ( ) . mockImplementation ( async ( opts ) => { const objectsToImport = await readStreamToCompletion ( opts . readStream ) ; return { success : true , successCount : objectsToImport . length , } ; } ) ; } ; export const createResolveSavedObjectsImportErrorsMock = ( ) => { return jest . fn ( ) . mockImplementation ( async ( opts ) => { const objectsToImport = await readStreamToCompletion ( opts . readStream ) ; return { success : true , successCount : objectsToImport . length , } ; } ) ; } ;