import { bootstrap } from 'global-agent' ; import { isW3C } from "./utils" ; export function processConfig ( config = { } , args = { } ) { const username = config . username || process . env . SAUCE_USERNAME ; const accessKey = config . accessKey || process . env . SAUCE_ACCESS_KEY ; const startConnect = config . startConnect !== false ; let tunnelIdentifier = args . tunnelIdentifier || config . tunnelIdentifier ; const sauceApiProxy = args . proxy || config . proxy ; if ( sauceApiProxy ) { const envVar = sauceApiProxy . startsWith ( 'https' ) ? 'KARMA_HTTPS_PROXY' : 'KARMA_HTTP_PROXY' ; process . env [ envVar ] = sauceApiProxy ; bootstrap ( { environmentVariableNamespace : 'KARMA_' , forceGlobalAgent : false } ) ; } const browserName = `${ args . browserName } ${ args . browserVersion || args . version || '' } ${ args . platformName || args . platform || '' }` ; if ( ! tunnelIdentifier && startConnect ) { tunnelIdentifier = 'karma-sauce-' + Math . round ( new Date ( ) . getTime ( ) / 1000 ) ; } const capabilitiesFromConfig = { build : config . build || args . build , name : config . testName || args . testName || 'Saucelabs Launcher Tests' , tags : config . tags || args . tags || [ ] , 'custom-data' : config . customData || args . customData , customData : config . customData || args . customData || { } , maxDuration : config . maxDuration || 1800 , commandTimeout : config . commandTimeout || 300 , idleTimeout : config . idleTimeout || 90 , parentTunnel : config . parentTunnel , tunnelIdentifier : tunnelIdentifier , timeZone : config . timeZone || args . timeZone , public : config . public || 'public' , recordScreenshots : config . recordScreenshots || args . recordScreenshots , recordVideo : config . recordVideo || config . recordVideo , } ; const sauceConnectOptions = { tunnelIdentifier : tunnelIdentifier , ... config . connectOptions , } ; if ( isW3C ( args ) ) { args . browserVersion = args . browserVersion || args . version || 'latest' ; args . platformName = args . platformName || args . platform || 'Windows 10' ; args [ 'sauce:options' ] = { ... capabilitiesFromConfig , ... ( args [ 'sauce:options' ] || { } ) } ; delete args . version ; delete args . platform ; } else { args = { ... args , ... capabilitiesFromConfig } ; } delete args . base ; const seleniumCapabilities = { user : username , key : accessKey , region : config . region , headless : config . headless , logLevel : 'error' , capabilities : { ... args } , ... config . options } ; return { startConnect , sauceConnectOptions , seleniumCapabilities , browserName } ; }