Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chromedriver): don't ignore patch version #413

Open
wants to merge 5 commits into
base: legacy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 69 additions & 26 deletions lib/binaries/chrome_xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,77 @@ 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' ||
(this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) {
itemFound = item;
}

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;
}

}
// 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 @@ -143,7 +186,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 @@ -65,4 +65,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();
});
});
});