import { FileHelper } from "./file-helper" ; import { TestResult } from "../../model/enums/test-status.enum" ; import { RunStatus } from "../../model/enums/run-status.enum" ; import { SpecCompleteResponse } from "../../model/spec-complete-response" ; import { PathFinder } from "../shared/path-finder" ; import * as io from "socket.io-client" ; import * as karma from "karma" ; function TestExplorerCustomReporter ( this , baseReporterDecorator , config , logger , emitter , injector ) { this . config = config ; this . emitter = emitter ; const defaultSocketPort = process . env . defaultSocketPort as string ; this . socket = io ( "http://localhost:" + defaultSocketPort + "/" , { forceNew : true , reconnection : true } ) ; this . socket . heartbeatTimeout = 24 * 60 * 60 * 1000 ; this . socket . heartbeatInterval = 24 * 60 * 60 * 1000 ; configureTimeouts ( injector ) ; const emitEvent = ( eventName , eventResults = null ) => { this . socket . emit ( eventName , { name : eventName , results : eventResults } ) ; } ; const FILE_PATTERN = "**/*spec.ts" ; const ENCODING = "utf-8" ; const pathFinder = new PathFinder ( new FileHelper ( ) ) ; const paths = pathFinder . getTestFilesPaths ( FILE_PATTERN , ENCODING ) ; baseReporterDecorator ( this ) ; this . adapters = [ ] ; this . onSpecComplete = ( browser , spec ) => { let status = TestResult . Failed ; if ( spec . skipped ) { status = TestResult . Skipped ; this . specSkipped ( browser , spec ) ; } else if ( spec . success ) { status = TestResult . Success ; } let lineNumber ; const filePath = pathFinder . getTestFilePath ( paths , spec . suite [ 0 ] , spec . description ) ; if ( filePath ) { lineNumber = pathFinder . getSpecLine ( spec . description , filePath , ENCODING ) ; } const result = new SpecCompleteResponse ( spec . id , spec . log , spec . suite , spec . description , spec . fullName , status , spec . time , filePath , lineNumber ) as any ; if ( result . status === TestResult . Failed ) { result . fullResponse = spec ; } emitEvent ( "spec_complete" , result ) ; } ; this . onRunComplete = ( browserCollection , result ) => { emitEvent ( "run_complete" , collectRunState ( result ) ) ; } ; this . onBrowserError = ( browser , error ) => { emitEvent ( "browser_error" , error ) ; } ; this . onBrowserStart = ( browser , info ) => { emitEvent ( "browser_start" ) ; } ; this . emitter . on ( "browsers_change" , ( capturedBrowsers ) => { if ( ! capturedBrowsers . forEach ) { return ; } let proceed = true ; capturedBrowsers . forEach ( ( newBrowser ) => { if ( ! newBrowser . id || ! newBrowser . name || newBrowser . id === newBrowser . name ) { proceed = false ; } } ) ; if ( proceed ) { emitEvent ( "browser_connected" ) ; } } ) ; } function configureTimeouts ( injector ) { process . nextTick ( ( ) => { const webServer = injector . get ( "webServer" ) ; if ( webServer ) { webServer . timeout = 0 ; } const socketServer = injector . get ( "socketServer" ) ; if ( socketServer ) { try { socketServer . set ( "heartbeat timeout" , 24 * 60 * 60 * 1000 ) ; socketServer . set ( "heartbeat interval" , 24 * 60 * 60 * 1000 ) ; } catch { console . error ( 'Karma 6 support not yet ready!' ) ; } } } ) ; } function collectRunState ( runResult ) { if ( runResult . disconnected ) { return RunStatus . Timeout ; } else if ( runResult . error ) { return RunStatus . Error ; } else { return RunStatus . Complete ; } } TestExplorerCustomReporter . $inject = [ "baseReporterDecorator" , "config" , "logger" , "emitter" , "injector" ] ; export const instance = TestExplorerCustomReporter ; export const name = "AngularReporter" ;