import plugin from '@start/plugin/src/' ; import { CoverageMapData } from 'istanbul-lib-coverage' ; export default ( formats = [ 'lcovonly' , 'text-summary' ] ) => plugin ( 'istanbulReport' , ( { logMessage } ) => async ( ) => { const { createCoverageMap } = await import ( 'istanbul-lib-coverage' ) ; const { createSourceMapStore } = await import ( 'istanbul-lib-source-maps' ) ; const { createReporter } = await import ( 'istanbul-api' ) ; const hooks = await import ( './hooks' ) ; const { default : coverageVariable } = await import ( './variable' ) ; hooks . clearAll ( ) ; const coverageMapData = ( global as any ) [ coverageVariable ] as CoverageMapData ; if ( ! coverageMapData ) { logMessage ( 'no coverage information was collected' ) ; return ; } const coverageMap = createCoverageMap ( coverageMapData ) ; const sourceMapStore = createSourceMapStore ( ) ; const remappedCoverageMap = sourceMapStore . transformCoverage ( coverageMap ) . map ; const reporter = createReporter ( ) ; logMessage ( formats . join ( ', ' ) ) ; formats . forEach ( ( format ) => { reporter . add ( format ) ; reporter . write ( remappedCoverageMap , { } ) ; } ) ; } ) ;