Skip to content

Get latest fix #418

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

Merged
merged 7 commits into from
Sep 16, 2019
Merged
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
41 changes: 4 additions & 37 deletions lib/binaries/chrome_xml.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as semver from 'semver';

import {Config} from '../config';
import {requestBody} from '../http_utils';

import {BinaryUrl} from './binary';
import {XmlConfigSource} from './config_source';
Expand Down Expand Up @@ -62,43 +63,9 @@ export class ChromeXml extends XmlConfigSource {
* Gets the latest item from the XML.
*/
private getLatestChromeDriverVersion(): Promise<BinaryUrl> {
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;
}
}
}
}
}
return {url: Config.cdnUrls().chrome + latest, version: latestVersion};
const latestReleaseUrl = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE';
return requestBody(latestReleaseUrl).then(latestVersion => {
return this.getSpecificChromeDriverVersion(latestVersion);
});
}

Expand Down
33 changes: 33 additions & 0 deletions lib/http_utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as request from 'request';
import {OptionsWithUrl} from 'request';
import * as url from 'url';

Expand Down Expand Up @@ -96,4 +97,36 @@ export class HttpUtils {
}
return undefined;
}

}

/**
* Request the body from the url.
* @param requestUrl The request url.
* @returns A promise string of the response body.
*/
export function requestBody(
requestUrl: string): Promise<string> {
const options = HttpUtils.initOptions(requestUrl);
options.followRedirect = true;
return new Promise((resolve, reject) => {
const req = request(options);
req.on('response', response => {
if (response.statusCode === 200) {
let output = '';
response.on('data', (data) => {
output += data;
});
response.on('end', () => {
resolve(output);
});
} else {
reject(new Error('response status code is not 200'));
}
});
req.on('error', error => {
reject(error);
});
});
}

1 change: 0 additions & 1 deletion spec/binaries/chrome_xml_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';
import * as rimraf from 'rimraf';
import {ChromeXml} from '../../lib/binaries/chrome_xml';
import {Config} from '../../lib/config';

describe('chrome xml reader', () => {
let out_dir = path.resolve('selenium_test');
Expand Down
1 change: 0 additions & 1 deletion spec/binaries/standalone_xml_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';
import * as rimraf from 'rimraf';
import {StandaloneXml} from '../../lib/binaries/standalone_xml';
import {Config} from '../../lib/config';

describe('standalone xml reader', () => {
let out_dir = path.resolve('selenium_test');
Expand Down
1 change: 0 additions & 1 deletion spec/cmds/status_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as path from 'path';

import {Logger, WriteTo} from '../../lib/cli/logger';
import {program} from '../../lib/cmds/update';
import {Config} from '../../lib/config';
import {spawnSync} from '../../lib/utils';

function getVersions(line: string): string[] {
Expand Down
1 change: 0 additions & 1 deletion spec/cmds/update_spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import * as process from 'process';
import * as rimraf from 'rimraf';

import {Logger, WriteTo} from '../../lib/cli/logger';
Expand Down
2 changes: 0 additions & 2 deletions spec/files/downloader_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as rimraf from 'rimraf';

import {Config} from '../../lib/config';
import {Downloader} from '../../lib/files';
import {HttpUtils} from '../../lib/http_utils';

describe('downloader', () => {
describe('get file', () => {
Expand Down