Skip to content

Commit

Permalink
fix(chromedriver): don't ignore patch version for specific download
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr_Travienikov committed Aug 22, 2019
1 parent 2f18bd5 commit a75c711
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 27 deletions.
98 changes: 71 additions & 27 deletions lib/binaries/chrome_xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -107,34 +107,78 @@ export class ChromeXml extends XmlConfigSource {
*/
private getSpecificChromeDriverVersion(inputVersion: string): Promise<BinaryUrl> {
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;
}
}
}
}
Expand Down Expand Up @@ -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];
Expand Down
22 changes: 22 additions & 0 deletions spec/binaries/chrome_xml_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit a75c711

Please sign in to comment.