import mock , { MockApplication } from 'egg-mock' ; import { Application , Agent } from 'egg' ; export function waitFor ( milliseconds ) { return new Promise ( resolve => { setTimeout ( ( ) => { resolve ( ) ; } , milliseconds ) ; } ) ; } export function initIpc ( app ) { const appMessenger = app . messenger ; const agentMessenger = ( app as any ) . agent . messenger ; appMessenger . sendRandom = ( ( action , data ) => { appMessenger . sendToAgent ( action , data ) ; } ) ; agentMessenger . sendRandom = ( ( action , data ) => { agentMessenger . sendToApp ( action , data ) ; } ) ; } export async function prepareTestApplication ( ) { const app = mock . app ( { cache : false , } ) ; await app . ready ( ) ; initIpc ( app ) ; return { app , agent : ( app as any ) . agent , } ; } export function testClear ( app ? , agent ? ) { if ( app ) { app . close ( ) ; } if ( agent ) { agent . close ( ) ; } mock . restore ( ) ; }