diff --git a/lib/binaries/android_sdk.ts b/lib/binaries/android_sdk.ts index 02802432..f091647d 100644 --- a/lib/binaries/android_sdk.ts +++ b/lib/binaries/android_sdk.ts @@ -20,13 +20,13 @@ export class AndroidSDK extends Binary { static DEFAULT_API_LEVELS = '24'; static DEFAULT_ABIS = 'x86_64'; - constructor() { - super(); + constructor(alternateCDN?: string) { + super(alternateCDN || Config.cdnUrls().android); + this.name = 'android-sdk'; this.versionCustom = AndroidSDK.versionDefault; this.prefixDefault = 'android-sdk_r'; this.suffixDefault = '.zip'; - this.cdn = Config.cdnUrls().android; } id(): string { return AndroidSDK.id; } diff --git a/lib/binaries/appium.ts b/lib/binaries/appium.ts index ffd36e74..29853b0c 100644 --- a/lib/binaries/appium.ts +++ b/lib/binaries/appium.ts @@ -18,8 +18,9 @@ export class Appium extends Binary { static isDefault = false; static shortName = ['appium']; - constructor() { - super(); + constructor(alternateCDN?: string) { + super(alternateCDN || Config.cdnUrls().appium); + this.name = 'appium'; this.versionCustom = Appium.versionDefault; this.prefixDefault = 'appium-'; diff --git a/lib/binaries/binary.ts b/lib/binaries/binary.ts index d27c4be8..f3f1a476 100644 --- a/lib/binaries/binary.ts +++ b/lib/binaries/binary.ts @@ -31,6 +31,8 @@ export class Binary { cdn: string; // url protocol and host arch: string; + constructor(public cdn: string) {} + /** * @param ostype The operating system. * @returns The executable file type. diff --git a/lib/binaries/chrome_driver.ts b/lib/binaries/chrome_driver.ts index 39613a49..8507029c 100644 --- a/lib/binaries/chrome_driver.ts +++ b/lib/binaries/chrome_driver.ts @@ -15,13 +15,13 @@ export class ChromeDriver extends Binary { static isDefault = true; static shortName = ['chrome']; - constructor() { - super(); + constructor(alternateCDN?: string) { + super(alternateCDN || Config.cdnUrls().chrome); + this.name = 'chromedriver'; this.versionCustom = ChromeDriver.versionDefault; this.prefixDefault = 'chromedriver_'; this.suffixDefault = '.zip'; - this.cdn = Config.cdnUrls().chrome; } id(): string { return ChromeDriver.id; } diff --git a/lib/binaries/gecko_driver.ts b/lib/binaries/gecko_driver.ts index 20bdf48c..90061cba 100644 --- a/lib/binaries/gecko_driver.ts +++ b/lib/binaries/gecko_driver.ts @@ -20,12 +20,12 @@ export class GeckoDriver extends Binary { 'Windows_NT': '-win64.zip' }; - constructor() { - super(); + constructor(alternateCDN?: string) { + super(alternateCDN || Config.cdnUrls().gecko); + this.name = 'geckodriver'; this.versionCustom = GeckoDriver.versionDefault; this.prefixDefault = 'geckodriver-'; - this.cdn = Config.cdnUrls().gecko; } id(): string { return GeckoDriver.id; } diff --git a/lib/binaries/ie_driver.ts b/lib/binaries/ie_driver.ts index 4b1f5f88..8ed96f1a 100644 --- a/lib/binaries/ie_driver.ts +++ b/lib/binaries/ie_driver.ts @@ -15,13 +15,13 @@ export class IEDriver extends Binary { static isDefault = false; static shortName = ['ie', 'ie32']; - constructor() { - super(); + constructor(alternateCDN?: string) { + super(alternateCDN || Config.cdnUrls().ie); + this.name = 'IEDriverServer'; this.versionCustom = IEDriver.versionDefault; this.prefixDefault = 'IEDriverServer'; this.suffixDefault = '.zip'; - this.cdn = Config.cdnUrls().ie; this.arch = os.arch(); } diff --git a/lib/binaries/stand_alone.ts b/lib/binaries/stand_alone.ts index db793b34..fdf2c6b1 100644 --- a/lib/binaries/stand_alone.ts +++ b/lib/binaries/stand_alone.ts @@ -13,13 +13,13 @@ export class StandAlone extends Binary { static isDefault = true; static shortName = ['standalone']; - constructor() { - super(); + constructor(alternateCDN?: string) { + super(alternateCDN || Config.cdnUrls().selenium); + this.name = 'selenium standalone'; this.versionCustom = StandAlone.versionDefault; this.prefixDefault = 'selenium-server-standalone-'; this.suffixDefault = '.jar'; - this.cdn = Config.cdnUrls().selenium; } id(): string { return StandAlone.id; } diff --git a/lib/cmds/update.ts b/lib/cmds/update.ts index 74c3ca69..b602d521 100644 --- a/lib/cmds/update.ts +++ b/lib/cmds/update.ts @@ -99,7 +99,7 @@ function update(options: Options): void { let proxy = options[Opt.PROXY].getString(); // setup versions for binaries - let binaries = FileManager.setupBinaries(); + let binaries = FileManager.setupBinaries(options[Opt.ALTERNATE_CDN].getString()); binaries[StandAlone.id].versionCustom = options[Opt.VERSIONS_STANDALONE].getString(); binaries[ChromeDriver.id].versionCustom = options[Opt.VERSIONS_CHROME].getString(); if (options[Opt.VERSIONS_IE]) { diff --git a/lib/files/file_manager.ts b/lib/files/file_manager.ts index 47102f01..f77cb398 100644 --- a/lib/files/file_manager.ts +++ b/lib/files/file_manager.ts @@ -52,27 +52,28 @@ export class FileManager { * For the operating system, create a list that includes the binaries * for selenium standalone, chrome, and internet explorer. * @param osType The operating system. + * @param alternateCDN URL of the alternative CDN to be used instead of the default ones. * @returns A binary map that are available for the operating system. */ - static compileBinaries_(osType: string): BinaryMap { + static compileBinaries_(osType: string, alternateCDN?: string): BinaryMap { let binaries: BinaryMap = {}; if (FileManager.checkOS_(osType, StandAlone)) { - binaries[StandAlone.id] = new StandAlone(); + binaries[StandAlone.id] = new StandAlone(alternateCDN); } if (FileManager.checkOS_(osType, ChromeDriver)) { - binaries[ChromeDriver.id] = new ChromeDriver(); + binaries[ChromeDriver.id] = new ChromeDriver(alternateCDN); } if (FileManager.checkOS_(osType, GeckoDriver)) { - binaries[GeckoDriver.id] = new GeckoDriver(); + binaries[GeckoDriver.id] = new GeckoDriver(alternateCDN); } if (FileManager.checkOS_(osType, IEDriver)) { - binaries[IEDriver.id] = new IEDriver(); + binaries[IEDriver.id] = new IEDriver(alternateCDN); } if (FileManager.checkOS_(osType, AndroidSDK)) { - binaries[AndroidSDK.id] = new AndroidSDK(); + binaries[AndroidSDK.id] = new AndroidSDK(alternateCDN); } if (FileManager.checkOS_(osType, Appium)) { - binaries[Appium.id] = new Appium(); + binaries[Appium.id] = new Appium(alternateCDN); } return binaries; } @@ -80,9 +81,12 @@ export class FileManager { /** * Look up the operating system and compile a list of binaries that are available * for the system. + * @param alternateCDN URL of the alternative CDN to be used instead of the default ones. * @returns A binary map that is available for the operating system. */ - static setupBinaries(): BinaryMap { return FileManager.compileBinaries_(os.type()); } + static setupBinaries(alternateCDN?: string): BinaryMap { + return FileManager.compileBinaries_(os.type(), alternateCDN); + } /** * Get the list of existing files from the output directory diff --git a/spec/files/fileManager_spec.ts b/spec/files/fileManager_spec.ts index adcf9fab..c794d340 100644 --- a/spec/files/fileManager_spec.ts +++ b/spec/files/fileManager_spec.ts @@ -2,6 +2,9 @@ import * as fs from 'fs'; import * as path from 'path'; import {Binary, AndroidSDK, ChromeDriver, IEDriver, Appium, StandAlone} from '../../lib/binaries'; import {DownloadedBinary, FileManager} from '../../lib/files'; +import { BinaryMap } from '../../built/lib/binaries/binary'; +import { Config } from '../../lib/config'; +import { GeckoDriver } from '../../lib/binaries/gecko_driver'; describe('file manager', () => { @@ -211,4 +214,53 @@ describe('file manager', () => { }); }); }); + + describe('configuring the CDN location', () => { + + describe('when no custom CDN is specified', () => { + + let defaults = Config.cdnUrls(); + let binaries = FileManager.compileBinaries_('Windows_NT'); + + it('should use the default configuration for Android SDK', () => { + expect(binaries[AndroidSDK.id].cdn).toEqual(defaults[AndroidSDK.id]); + }); + + it('should use the default configuration for Appium', () => { + expect(binaries[Appium.id].cdn).toEqual(defaults[Appium.id]); + }); + + it('should use the default configuration for Chrome Driver', () => { + expect(binaries[ChromeDriver.id].cdn).toEqual(defaults[ChromeDriver.id]); + }); + + it('should use the default configuration for Gecko Driver', () => { + expect(binaries[GeckoDriver.id].cdn).toEqual(defaults[GeckoDriver.id]); + }); + + it('should use the default configuration for IE Driver', () => { + expect(binaries[IEDriver.id].cdn).toEqual(defaults[IEDriver.id]); + }); + + it('should use the default configuration for Selenium Standalone', () => { + expect(binaries[StandAlone.id].cdn).toEqual(defaults['selenium']); + }); + }); + + describe('when custom CDN is specified', () => { + + it('should configure the CDN for each binary', () => { + let customCDN = 'https://my.corporate.cdn/'; + let binaries = FileManager.compileBinaries_('Windows_NT', customCDN); + + forEachOf(binaries, binary => expect(binary.cdn).toEqual(customCDN, binary.name)); + }); + }); + + function forEachOf(binaries: BinaryMap, fn: (binary: T) => void) { + for (var key in binaries) { + fn(binaries[key]); + } + } + }); });