import axios from 'axios' ; import { ConfiguredPluginResource } from 'flex-plugins-api-client' ; import { logger } from 'flex-dev-utils' ; import { Browser } from './browser' ; import { sleep } from './timers' ; param url param timeout param pollInterval const waitForPluginToStart = async ( url , timeout , pollInterval ) : Promise < void > => { let counter = 0 ; while ( true ) { try { await axios . get ( url ) ; break ; } catch ( e ) { if ( counter === timeout ) { logger . error ( e ) ; throw new Error ( 'Plugin did not start' ) ; } } await sleep ( pollInterval ) ; counter += pollInterval ; } } ; param flexBaseUrl param releasedPlugin param timeout param pollInterval const waitForPluginToRelease = async ( releasedPlugin , timeout , pollInterval ) : Promise < void > => { let counter = 0 ; while ( true ) { try { const plugins = await Browser . app . plugins . list ( ) ; const plugin = plugins . find ( ( plugin ) => plugin . name === releasedPlugin . unique_name ) ; if ( ! plugin ) { throw new Error ( `/plugins did not contain ${ releasedPlugin . unique_name }` ) ; } logger . info ( '/plugins endpoint returned' , JSON . stringify ( plugins ) ) ; break ; } catch ( e ) { if ( counter >= timeout ) { throw e ; } } await sleep ( pollInterval ) ; counter += pollInterval ; } } ; export default { waitForPluginToStart , waitForPluginToRelease , } ;