import { FancyTypes } from '@oclif/test' ; export type Plugin < T > = FancyTypes . Plugin < T > ; export interface AsyncPlugin < T > { init ? ( ctx ) : any ; initAsync ? ( ctx ) : Promise < any > ; run ? ( ctx ) : any ; runAsync ? ( ctx ) : Promise < any > ; catch ? ( ctx ) : any ; catchAsync ? ( ctx ) : Promise < any > ; finally ? ( ctx ) : any ; finallyAsync ? ( ctx ) : Promise < any > ; } param plugin returns export function mapFancyTestAsyncPlugin < T > ( plugin ) { const wrapped = { } ; if ( plugin . initAsync ) { const initAsync = plugin . initAsync . bind ( plugin ) ; wrapped . init = ctx => initAsync ( ctx ) ; } else if ( plugin . init ) { wrapped . init = plugin . init . bind ( plugin ) ; } if ( plugin . runAsync ) { const runAsync = plugin . runAsync . bind ( plugin ) ; wrapped . run = ctx => runAsync ( ctx ) ; } else if ( plugin . run ) { wrapped . run = plugin . run . bind ( plugin ) ; } if ( plugin . catchAsync ) { const catchAsync = plugin . catchAsync . bind ( plugin ) ; wrapped . catch = ctx => catchAsync ( ctx ) ; } else if ( plugin . catch ) { wrapped . catch = plugin . catch . bind ( plugin ) ; } if ( plugin . finallyAsync ) { const finallyAsync = plugin . finallyAsync . bind ( plugin ) ; wrapped . finally = ctx => finallyAsync ( ctx ) ; } else if ( plugin . finally ) { wrapped . finally = plugin . finally . bind ( plugin ) ; } return wrapped ; }