import { PromiseUtils , ServiceConfiguration , System } from 'common' ; import { inject , injectable } from 'inversify' ; import { GlobalLogger } from 'logger' ; import { AxeScanResults , Page } from 'scanner-global-library' ; @ injectable ( ) export class AxeScanner { constructor ( @ inject ( PromiseUtils ) private readonly promiseUtils , @ inject ( ServiceConfiguration ) private readonly serviceConfig , @ inject ( GlobalLogger ) private readonly logger ) { } public async scan ( page ) { const scanConfig = await this . serviceConfig . getConfigValue ( 'scanConfig' ) ; return this . promiseUtils . waitFor ( this . scanImpl ( page ) , scanConfig . scanTimeoutInMin * 60000 , ( ) => { this . logger . logError ( `Accessibility scan timed out after ${ scanConfig . scanTimeoutInMin } minutes` ) ; return Promise . resolve ( { error : { errorType : 'ScanTimeout' , message : `Scan timed out after ${ scanConfig . scanTimeoutInMin } minutes` , stack : new Error ( ) . stack , } , } as AxeScanResults ) ; } ) ; } private async scanImpl ( page ) { try { this . logger . logInfo ( `Starting accessibility website page scanning.` ) ; const scanResult = await page . scanForA11yIssues ( ) ; this . logger . logInfo ( `Accessibility scanning of website page successfully completed.` ) ; return scanResult ; } catch ( error ) { this . logger . logError ( `An error occurred while scanning website page.` , { error : System . serializeError ( error ) } ) ; throw error ; } } }