import 'reflect-metadata' ; import { IMock , Mock } from 'typemoq' ; import { ReporterFactory , CombinedReportParameters , Reporter , Report } from 'accessibility-insights-report' ; import { ConsolidatedReportGenerator } from './consolidated-report-generator' ; import { TaskConfig } from '../task-config' ; import { Logger } from '../logger/logger' ; import * as fs from 'fs' ; const htmlReportString = 'html report' ; const reportOutDir = 'reportOutDir' ; const reportFileName = `${ reportOutDir }/index.html` ; let taskConfigMock ; let reporterMock ; let loggerMock ; let fsMock ; let consolidatedReportGenerator ; let htmlReport ; let combinedReportParameters ; describe ( ConsolidatedReportGenerator , ( ) => { beforeEach ( ( ) => { taskConfigMock = Mock . ofType < TaskConfig > ( ) ; reporterMock = Mock . ofType < Reporter > ( ) ; loggerMock = Mock . ofType < Logger > ( ) ; fsMock = Mock . ofType < typeof fs > ( ) ; htmlReport = { asHTML : ( ) => htmlReportString , } ; const reporterFactoryMock = ( ) => reporterMock . object ; combinedReportParameters = { serviceName : 'combinedReportData' } as CombinedReportParameters ; reporterMock . setup ( ( o ) => o . fromCombinedResults ( combinedReportParameters ) ) . returns ( ( ) => htmlReport ) . verifiable ( ) ; taskConfigMock . setup ( ( o ) => o . getReportOutDir ( ) ) . returns ( ( ) => reportOutDir ) . verifiable ( ) ; fsMock . setup ( ( o ) => o . existsSync ( reportOutDir ) ) . returns ( ( ) => false ) . verifiable ( ) ; fsMock . setup ( ( o ) => o . mkdirSync ( reportOutDir ) ) . verifiable ( ) ; fsMock . setup ( ( o ) => o . writeFileSync ( reportFileName , htmlReportString ) ) . verifiable ( ) ; consolidatedReportGenerator = new ConsolidatedReportGenerator ( taskConfigMock . object , reporterFactoryMock , loggerMock . object , fsMock . object ) ; } ) ; afterEach ( ( ) => { taskConfigMock . verifyAll ( ) ; loggerMock . verifyAll ( ) ; fsMock . verifyAll ( ) ; } ) ; it ( 'generate report' , ( ) => { const actualReportFileName = consolidatedReportGenerator . generateReport ( combinedReportParameters ) ; expect ( actualReportFileName ) . toEqual ( reportFileName ) ; } ) ; } ) ;