From a75c7115bed049d6c3550af57c2bd3acea3d3ed4 Mon Sep 17 00:00:00 2001 From: Oleksandr_Travienikov Date: Thu, 22 Aug 2019 15:07:04 +0300 Subject: [PATCH] fix(chromedriver): don't ignore patch version for specific download --- lib/binaries/chrome_xml.ts | 98 +++++++++++++++++++++++--------- spec/binaries/chrome_xml_spec.ts | 22 +++++++ 2 files changed, 93 insertions(+), 27 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index e79063fc..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; + } } } } @@ -176,7 +220,7 @@ export function getValidSemver(version: string): string { } // This supports downloading 74.0.3729.6 try { - const newRegex = /(\d+.\d+.\d+).\d+/g; + const newRegex = /(\d+.\d+.\d+)/g; const exec = newRegex.exec(version); if (exec) { lookUpVersion = exec[1]; 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(); + }); + }); });