import { CommandlineProcessHandler } from "../integration/commandline-process-handler" ; import { TestServer } from "../../model/test-server" ; import { KarmaEventListener } from "../integration/karma-event-listener" ; import { Logger } from "../shared/logger" ; import { TestExplorerConfiguration } from "../../model/test-explorer-configuration" ; import { KarmaProcessConfigurator } from "../karma/karma-process-configurator" ; export class KarmaServer implements TestServer { public constructor ( private readonly karmaEventListener , private readonly logger , private readonly processHandler , private readonly processConfigurator ) { } public async start ( config ) { const baseKarmaConfigFilePath = require . resolve ( config . baseKarmaConfFilePath ) ; const { command , processArguments } = this . processConfigurator . createProcessCommandAndArguments ( baseKarmaConfigFilePath ) ; const options = this . processConfigurator . createProcessOptions ( config . projectRootPath , config . userKarmaConfFilePath , config . defaultSocketConnectionPort ) ; this . processHandler . create ( command , processArguments , options ) ; await this . karmaEventListener . listenTillKarmaReady ( config . defaultSocketConnectionPort ) ; return config . projectRootPath ; } public stop ( ) { if ( this . karmaEventListener . isServerLoaded ) { const stopper = require ( "karma" ) . stopper ; stopper . stop ( { port : 9876 } , ( exitCode ) => { this . logger . info ( `Karma exited succesfully` ) ; } ) ; this . karmaEventListener . stopListeningToKarma ( ) ; } } public async stopAsync ( ) { return new Promise < void > ( resolve => { if ( this . karmaEventListener . isServerLoaded ) { const stopper = require ( "karma" ) . stopper ; stopper . stop ( { port : 9876 } , ( exitCode ) => { this . logger . info ( `Karma exited succesfully` ) ; resolve ( ) ; this . karmaEventListener . stopListeningToKarma ( ) ; } ) ; } } ) ; } }