import { Config , ConfigOptions } from "karma" ; import * as path from "path" ; import * as TestExplorerCustomReporter from "../core/integration/test-explorer-custom-karma-reporter" ; import { UtilityHelper } from "../core/shared/utility-helper" ; export class KarmaConfigurator { private readonly testExplorerHelper : UtilityHelper ; constructor ( ) { this . testExplorerHelper = new UtilityHelper ( ) ; } public setMandatoryOptions ( config ) { config . logLevel = config . LOG_INFO ; config . autoWatch = false ; config . autoWatchBatchDelay = 0 ; config . browsers = [ "ChromeTestExplorer" ] ; config . browserNoActivityTimeout = undefined ; config . singleRun = false ; config . customLaunchers = { ChromeTestExplorer : { base : "ChromeHeadless" , debug : true , flags : [ "--remote-debugging-port=9222" ] , } , } ; } public dontLoadOriginalConfigurationFileIntoBrowser ( config , originalConfigPath ) { config . exclude = config . exclude || [ ] ; config . exclude . push ( originalConfigPath ) ; } public setBasePath ( config , originalConfigPath ) { if ( ! config . basePath ) { if ( originalConfigPath ) { config . basePath = path . resolve ( path . dirname ( originalConfigPath ) ) ; } else { config . basePath = process . cwd ( ) ; } } } public disableSingleRunPermanently ( config ) { const prevSet = config . set ; if ( typeof prevSet === "function" ) { config . set = ( newConfig ) => { if ( newConfig != null ) { if ( newConfig . singleRun === true ) { newConfig . singleRun = false ; } prevSet ( newConfig ) ; } } ; } } public cleanUpReporters ( config ) { const filteredReporters = this . testExplorerHelper . removeElementsFromArrayWithoutModifyingIt ( config . reporters , [ "dots" , "kjhtml" ] ) ; config . reporters = filteredReporters ; } public loadOriginalUserConfiguration ( config , originalConfigPath ) { let originalConfigModule = require ( originalConfigPath ) ; if ( typeof originalConfigModule === "object" && typeof originalConfigModule . default !== "undefined" ) { originalConfigModule = originalConfigModule . default ; } originalConfigModule ( config ) ; } public configureTestExplorerCustomReporter ( config ) { this . addPlugin ( config , { [ `reporter:${ TestExplorerCustomReporter . name }` ] : [ "type" , TestExplorerCustomReporter . instance ] } ) ; if ( ! config . reporters ) { config . reporters = [ ] ; } config . reporters . push ( TestExplorerCustomReporter . name ) ; } private addPlugin ( karmaConfig , karmaPlugin ) { karmaConfig . plugins = karmaConfig . plugins || [ "karma-*" ] ; karmaConfig . plugins . push ( karmaPlugin ) ; } }