From 6a95aa4187825d1293bda7c802f39257699095fc Mon Sep 17 00:00:00 2001 From: TravkinAlex Date: Fri, 16 Aug 2019 15:26:10 +0300 Subject: [PATCH 1/4] fix(chromedriver): don't ignore patch version --- lib/binaries/chrome_xml.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index e79063fc..5c1e9c8f 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -175,11 +175,12 @@ export function getValidSemver(version: string): string { // no-op: is this is not valid, do not throw here. } // This supports downloading 74.0.3729.6 + // Removing the 0 after 74, to keep patch version of webdriver try { - const newRegex = /(\d+.\d+.\d+).\d+/g; + const newRegex = /(\d+.)\d+.(\d+.\d+)/g; const exec = newRegex.exec(version); if (exec) { - lookUpVersion = exec[1]; + lookUpVersion = exec[1] + exec[2]; } } catch (_) { // no-op: if this does not work, use the other regex pattern. From 4aecf4dddfaa40bdf66d9c6976771c699d10e43e Mon Sep 17 00:00:00 2001 From: Oleksandr_Travienikov Date: Thu, 22 Aug 2019 15:21:04 +0300 Subject: [PATCH 2/4] fix(chromedriver): don't ignore patch version for specific download --- lib/binaries/chrome_xml.ts | 101 ++++++++++++++++++++++--------- spec/binaries/chrome_xml_spec.ts | 22 +++++++ 2 files changed, 94 insertions(+), 29 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 5c1e9c8f..8cbeb89d 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -81,8 +81,8 @@ export class ChromeXml extends XmlConfigSource { latest = item; latestVersion = item.split('/')[0]; } else if ( - iterVersion.startsWith(this.maxVersion) && - semver.gt(iterVersion, chromedriverVersion)) { + iterVersion.startsWith(this.maxVersion) && + semver.gt(iterVersion, chromedriverVersion)) { // After the first time, make sure the semantic version is greater. chromedriverVersion = iterVersion; latest = item; @@ -107,34 +107,78 @@ export class ChromeXml extends XmlConfigSource { */ private getSpecificChromeDriverVersion(inputVersion: string): Promise { return this.getVersionList().then(list => { - const specificVersion = getValidSemver(inputVersion); - if (specificVersion === '') { - throw new Error(`version ${inputVersion} ChromeDriver does not exist`) - } + + const isLong = inputVersion.split('.').length === 4; let itemFound = ''; - for (let item of list) { - // Get a semantic version. - let version = item.split('/')[0]; - if (semver.valid(version) == null) { - const lookUpVersion = getValidSemver(version); - - if (semver.valid(lookUpVersion)) { - // Check to see if the specified version matches. - if (lookUpVersion === specificVersion) { - // When item found is null, check the os arch - // 64-bit version works OR not 64-bit version and the path does not have '64' - if (itemFound == '') { - if (this.osarch === 'x64' || + + if (!isLong) { + const specificVersion = getValidSemver(inputVersion); + if (specificVersion === '') { + throw new Error(`version ${inputVersion} ChromeDriver does not exist`) + } + for (let item of list) { + // Get a semantic version. + let version = item.split('/')[0]; + if (semver.valid(version) == null) { + const lookUpVersion = getValidSemver(version); + + if (semver.valid(lookUpVersion)) { + // Check to see if the specified version matches. + if (lookUpVersion === specificVersion) { + // When item found is null, check the os arch + // 64-bit version works OR not 64-bit version and the path does not have '64' + if (itemFound == '') { + if (this.osarch === 'x64' || (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { - itemFound = item; - } + itemFound = item; + } + } + // If the semantic version is the same, check os arch. + // For 64-bit systems, prefer the 64-bit version. + else if (this.osarch === 'x64') { + if (item.includes(this.getOsTypeName() + '64')) { + itemFound = item; + } + } } - // If the semantic version is the same, check os arch. - // For 64-bit systems, prefer the 64-bit version. - else if (this.osarch === 'x64') { - if (item.includes(this.getOsTypeName() + '64')) { - itemFound = item; + } + } + } + } else { + // Splitting to two semver objects because of clunky chromedriver versioning + // Supports e.g. 76.0.3809.68 while not ignoring the last patch number + const inputVersionPart1 = inputVersion.split('.').slice(0, 3).join('.'); + const inputVersionPart2 = inputVersion.split('.').slice(1, 4).join('.'); + + const specificVersion1 = getValidSemver(inputVersionPart1); + const specificVersion2 = getValidSemver(inputVersionPart2); + if (specificVersion1 === '' || specificVersion2 === '') { + throw new Error(`version ${inputVersion} ChromeDriver does not exist`); + } + + for (let item of list) { + // Get a semantic version. + let version = item.split('/')[0]; + if (semver.valid(version) == null) { + const versionPt1 = version.split('.').slice(0, 3).join('.'); + const versionPt2 = version.split('.').slice(1, 4).join('.'); + const lookUpVersion1 = getValidSemver(versionPt1); + const lookUpVersion2 = getValidSemver(versionPt2); + if (semver.valid(lookUpVersion1) && semver.valid(lookUpVersion2)) { + // Check to see if the specified version matches. + if (lookUpVersion1 === specificVersion1 && lookUpVersion2 === specificVersion2) { + // When item found is null, check the os arch + // 64-bit version works OR not 64-bit version and the path does not have '64' + if (itemFound == '') { + if (this.osarch === 'x64' || + (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { + itemFound = item; + } + } else if (this.osarch === 'x64') { + if (item.includes(this.getOsTypeName() + '64')) { + itemFound = item; + } } } } @@ -175,12 +219,11 @@ export function getValidSemver(version: string): string { // no-op: is this is not valid, do not throw here. } // This supports downloading 74.0.3729.6 - // Removing the 0 after 74, to keep patch version of webdriver try { - const newRegex = /(\d+.)\d+.(\d+.\d+)/g; + const newRegex = /(\d+.\d+.\d+)/g; const exec = newRegex.exec(version); if (exec) { - lookUpVersion = exec[1] + exec[2]; + lookUpVersion = exec[1]; } } catch (_) { // no-op: if this does not work, use the other regex pattern. diff --git a/spec/binaries/chrome_xml_spec.ts b/spec/binaries/chrome_xml_spec.ts index a607d089..75fdfa8f 100644 --- a/spec/binaries/chrome_xml_spec.ts +++ b/spec/binaries/chrome_xml_spec.ts @@ -66,4 +66,26 @@ describe('chrome xml reader', () => { done(); }); }); + + it('should get 76.0.3809.68 version', (done) => { + let chromeXml = new ChromeXml(); + chromeXml.out_dir = out_dir; + chromeXml.ostype = 'Windows_NT'; + chromeXml.osarch = 'x64'; + chromeXml.getUrl('76.0.3809.68').then((binaryUrl) => { + expect(binaryUrl.url).toContain('76.0.3809.68/chromedriver_win32.zip'); + done(); + }); + }); + + it('should get 76.0.3809.12 version', (done) => { + let chromeXml = new ChromeXml(); + chromeXml.out_dir = out_dir; + chromeXml.ostype = 'Windows_NT'; + chromeXml.osarch = 'x64'; + chromeXml.getUrl('76.0.3809.12').then((binaryUrl) => { + expect(binaryUrl.url).toContain('76.0.3809.12/chromedriver_win32.zip'); + done(); + }); + }); }); From 5a85584cff1814d2094150af77a3e290f4cd7e94 Mon Sep 17 00:00:00 2001 From: Oleksandr_Travienikov Date: Thu, 22 Aug 2019 16:21:34 +0300 Subject: [PATCH 3/4] fix(chromedriver): don't ignore patch version for latest download --- lib/binaries/chrome_xml.ts | 92 +++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 8cbeb89d..f35c58cd 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -63,43 +63,71 @@ export class ChromeXml extends XmlConfigSource { */ private getLatestChromeDriverVersion(): Promise { return this.getVersionList().then(list => { - let chromedriverVersion: string = null; - let latest = ''; - let latestVersion = ''; - for (let item of list) { - // Get a semantic version - const version = item.split('/')[0]; - if (semver.valid(version) == null) { - const iterVersion = getValidSemver(version); - - if (!semver.valid(iterVersion)) { - throw new Error('invalid Chromedriver version'); - } - // First time: use the version found. - if (chromedriverVersion == null) { - chromedriverVersion = iterVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if ( - iterVersion.startsWith(this.maxVersion) && - semver.gt(iterVersion, chromedriverVersion)) { - // After the first time, make sure the semantic version is greater. - chromedriverVersion = iterVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if (iterVersion === chromedriverVersion) { - // If the semantic version is the same, check os arch. - // For 64-bit systems, prefer the 64-bit version. - if (this.osarch === 'x64') { - if (item.includes(this.getOsTypeName() + '64')) { - latest = item; + let chromedriverVersion: string = null; + // To support 4-number versions (e.g. 76.0.3809.68) + let chromedriverPatchVersion: string = null; + let latest = ''; + let latestVersion = ''; + for (let item of list) { + // Get a semantic version + const version = item.split('/')[0]; + const isLong = version.split('.').length === 4; + + if (semver.valid(version) == null) { + let iterVersion; + let iterPatchVersion; + if (!isLong) { + iterVersion = getValidSemver(version); + } else { + // At first check first 3 numbers of version (for e.g. 76.0.3809.68) + iterVersion = getValidSemver(version.split('.').slice(0, 3).join('.')); + iterPatchVersion = getValidSemver(version.split('.').slice(1, 4).join('.')); + } + + if (!semver.valid(iterVersion)) { + throw new Error('invalid Chromedriver version'); + } + // First time: use the version found. + if (chromedriverVersion == null) { + chromedriverVersion = iterVersion; + latest = item; + latestVersion = item.split('/')[0]; + } else if ( + iterVersion.startsWith(this.maxVersion) && + semver.gt(iterVersion, chromedriverVersion)) { + // After the first time, make sure the semantic version is greater. + chromedriverVersion = iterVersion; + latest = item; + latestVersion = item.split('/')[0]; + } else if (iterVersion === chromedriverVersion) { + if (isLong && iterPatchVersion != chromedriverPatchVersion) + // Now check last 3 numbers of version to include patch (for e.g. 76.0.3809.68) + { + if (chromedriverPatchVersion == null) { + chromedriverPatchVersion = iterPatchVersion; + latest = item; + latestVersion = item.split('/')[0]; + } else if (semver.gt(iterPatchVersion, chromedriverPatchVersion)) { + // After the first time, make sure the semantic version is greater. + chromedriverPatchVersion = iterPatchVersion; + latest = item; + latestVersion = item.split('/')[0]; + } + } else { + // If the semantic version is the same, check os arch. + // For 64-bit systems, prefer the 64-bit version. + if (this.osarch === 'x64') { + if (item.includes(this.getOsTypeName() + '64')) { + latest = item; + } + } } } } } + return {url: Config.cdnUrls().chrome + latest, version: latestVersion}; } - return {url: Config.cdnUrls().chrome + latest, version: latestVersion}; - }); + ); } /** From 3052328a8016aefc4d5ebcfde97e5871c42d9daa Mon Sep 17 00:00:00 2001 From: Oleksandr_Travienikov Date: Thu, 22 Aug 2019 18:47:03 +0300 Subject: [PATCH 4/4] chore(styling): fix formatting --- lib/binaries/chrome_xml.ts | 112 ++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index f35c58cd..09b9d617 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -63,71 +63,70 @@ export class ChromeXml extends XmlConfigSource { */ private getLatestChromeDriverVersion(): Promise { return this.getVersionList().then(list => { - let chromedriverVersion: string = null; - // To support 4-number versions (e.g. 76.0.3809.68) - let chromedriverPatchVersion: string = null; - let latest = ''; - let latestVersion = ''; - for (let item of list) { - // Get a semantic version - const version = item.split('/')[0]; - const isLong = version.split('.').length === 4; + let chromedriverVersion: string = null; + // To support 4-number versions (e.g. 76.0.3809.68) + let chromedriverPatchVersion: string = null; + let latest = ''; + let latestVersion = ''; + for (let item of list) { + // Get a semantic version + const version = item.split('/')[0]; + const isLong = version.split('.').length === 4; - if (semver.valid(version) == null) { - let iterVersion; - let iterPatchVersion; - if (!isLong) { - iterVersion = getValidSemver(version); - } else { - // At first check first 3 numbers of version (for e.g. 76.0.3809.68) - iterVersion = getValidSemver(version.split('.').slice(0, 3).join('.')); - iterPatchVersion = getValidSemver(version.split('.').slice(1, 4).join('.')); - } + if (semver.valid(version) == null) { + let iterVersion; + let iterPatchVersion; + if (!isLong) { + iterVersion = getValidSemver(version); + } else { + // At first check first 3 numbers of version (for e.g. 76.0.3809.68) + iterVersion = getValidSemver(version.split('.').slice(0, 3).join('.')); + iterPatchVersion = getValidSemver(version.split('.').slice(1, 4).join('.')); + } - if (!semver.valid(iterVersion)) { - throw new Error('invalid Chromedriver version'); - } - // First time: use the version found. - if (chromedriverVersion == null) { - chromedriverVersion = iterVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if ( + if (!semver.valid(iterVersion)) { + throw new Error('invalid Chromedriver version'); + } + // First time: use the version found. + if (chromedriverVersion == null) { + chromedriverVersion = iterVersion; + latest = item; + latestVersion = item.split('/')[0]; + } else if ( iterVersion.startsWith(this.maxVersion) && semver.gt(iterVersion, chromedriverVersion)) { - // After the first time, make sure the semantic version is greater. - chromedriverVersion = iterVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if (iterVersion === chromedriverVersion) { - if (isLong && iterPatchVersion != chromedriverPatchVersion) - // Now check last 3 numbers of version to include patch (for e.g. 76.0.3809.68) - { - if (chromedriverPatchVersion == null) { - chromedriverPatchVersion = iterPatchVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if (semver.gt(iterPatchVersion, chromedriverPatchVersion)) { - // After the first time, make sure the semantic version is greater. - chromedriverPatchVersion = iterPatchVersion; + // After the first time, make sure the semantic version is greater. + chromedriverVersion = iterVersion; + latest = item; + latestVersion = item.split('/')[0]; + } else if (iterVersion === chromedriverVersion) { + if (isLong && iterPatchVersion != chromedriverPatchVersion) + // Now check last 3 numbers of version to include patch (for e.g. 76.0.3809.68) + { + if (chromedriverPatchVersion == null) { + chromedriverPatchVersion = iterPatchVersion; + latest = item; + latestVersion = item.split('/')[0]; + } else if (semver.gt(iterPatchVersion, chromedriverPatchVersion)) { + // After the first time, make sure the semantic version is greater. + chromedriverPatchVersion = iterPatchVersion; + latest = item; + latestVersion = item.split('/')[0]; + } + } else { + // If the semantic version is the same, check os arch. + // For 64-bit systems, prefer the 64-bit version. + if (this.osarch === 'x64') { + if (item.includes(this.getOsTypeName() + '64')) { latest = item; - latestVersion = item.split('/')[0]; - } - } else { - // If the semantic version is the same, check os arch. - // For 64-bit systems, prefer the 64-bit version. - if (this.osarch === 'x64') { - if (item.includes(this.getOsTypeName() + '64')) { - latest = item; - } } } } } } - return {url: Config.cdnUrls().chrome + latest, version: latestVersion}; } - ); + return {url: Config.cdnUrls().chrome + latest, version: latestVersion}; + }); } /** @@ -135,7 +134,6 @@ export class ChromeXml extends XmlConfigSource { */ private getSpecificChromeDriverVersion(inputVersion: string): Promise { return this.getVersionList().then(list => { - const isLong = inputVersion.split('.').length === 4; let itemFound = ''; @@ -157,7 +155,7 @@ export class ChromeXml extends XmlConfigSource { // 64-bit version works OR not 64-bit version and the path does not have '64' if (itemFound == '') { if (this.osarch === 'x64' || - (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { + (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { itemFound = item; } @@ -200,7 +198,7 @@ export class ChromeXml extends XmlConfigSource { // 64-bit version works OR not 64-bit version and the path does not have '64' if (itemFound == '') { if (this.osarch === 'x64' || - (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { + (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { itemFound = item; } } else if (this.osarch === 'x64') {