import 'mocha' ; import { expect } from 'chai' ; import { parseApplication } from '@/application/Parser/ApplicationParser' ; import { IApplication } from '@/domain/IApplication' ; import { IUrlStatus } from './StatusChecker/IUrlStatus' ; import { getUrlStatusesInParallel , IBatchRequestOptions } from './StatusChecker/BatchStatusChecker' ; describe ( 'collections' , ( ) => { const app = parseApplication ( ) ; const urls = collectUniqueUrls ( app ) ; const options = { domainOptions : { sameDomainParallelize : true , } , requestOptions : { retryExponentialBaseInMs : 3 * 1000 , additionalHeaders : { referer : app . info . homepage } , additionalHeadersUrlIgnore : [ 'http://batcmd.com/' , ] , } , } ; const testTimeoutInMs = urls . length * 60 * 1000 ; it ( 'have no dead urls' , async ( ) => { const results = await getUrlStatusesInParallel ( urls , options ) ; const deadUrls = results . filter ( ( r ) => r . code !== 200 ) ; expect ( deadUrls ) . to . have . lengthOf ( 0 , printUrls ( deadUrls ) ) ; } ) . timeout ( testTimeoutInMs ) ; } ) ; function collectUniqueUrls ( app ) { return app . collections . flatMap ( ( a ) => a . getAllScripts ( ) ) . flatMap ( ( script ) => script . documentationUrls ) . filter ( ( url , index , array ) => array . indexOf ( url ) === index ) ; } function printUrls ( statuses ) { return '\n' + statuses . map ( ( status ) => `- ${ status . url }\n` + ( status . code ? `\tResponse code: ${ status . code }` : '' ) + ( status . error ? `\tError: ${ status . error }` : '' ) ) . join ( '\n' ) + '\n' ; }