Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 8b850a6

Browse files
committed
fix: only download latest version with server
some of the recent releases (e.g. 3.150.*) no longer seem to have the selenium-server-standalone in them, so limit our fetches to those that do. Fixes: #51
1 parent 5a61e29 commit 8b850a6

File tree

1 file changed

+14
-50
lines changed

1 file changed

+14
-50
lines changed

lib/selenium/version.js

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
const request = require('request');
3636
const parseXml = require('xml2js').parseString;
37-
const _ = require('lodash');
3837
const Semver = require('semver');
3938

4039
function buildDownloadUrl(version, minorVersion) {
@@ -43,43 +42,21 @@ function buildDownloadUrl(version, minorVersion) {
4342

4443
const FALLBACK_SELENIUM_VERSION = '3.9.1';
4544

46-
function addPrefix(lookup, prefixEntry) {
47-
const prefix = `${prefixEntry.Prefix}`;
48-
const prefixMatch = prefix.match(/^(\d+\.\d+)\/$/);
49-
if (prefixMatch) {
50-
const minorVersion = prefixMatch[1];
51-
const semver = Semver.coerce(minorVersion);
52-
lookup[semver] = { error: null, minorVersion: minorVersion };
53-
}
54-
return lookup;
55-
}
56-
57-
function parseSeleniumMinor(result) {
58-
try {
59-
const prefixes = result.ListBucketResult.CommonPrefixes.reduce(
60-
addPrefix,
61-
{}
62-
);
63-
// Once 4.x is stable, we can go back to '*' or '<5' as our base range.
64-
const latest = Semver.maxSatisfying(Object.keys(prefixes), '<4');
65-
return prefixes[latest];
66-
} catch (parseError) {
67-
return { error: parseError, minorVersion: null };
68-
}
69-
}
70-
7145
function parseSelenium(result) {
7246
try {
7347
const contents = result.ListBucketResult.Contents;
74-
const standalone = _.find(contents, content => {
75-
return content.Key[0].match(
76-
/selenium-server-standalone-\d+.\d+.\d+\.jar$/
77-
);
78-
});
79-
return {
80-
error: null,
81-
version: standalone.Key[0].match(/(\d+\.\d+\.\d+)/)[0],
82-
};
48+
const standalone = contents
49+
.filter(content => {
50+
return content.Key[0].match(
51+
/selenium-server-standalone-\d+.\d+.\d+\.jar$/
52+
);
53+
})
54+
.map(s => s.Key[0].match(/(\d+\.\d+\.\d+)/)[0]);
55+
56+
// Once 4.x is stable, we can go back to '*' or '<5' as our base range.
57+
const latest = Semver.maxSatisfying(standalone, '<4');
58+
59+
return { error: null, version: latest };
8360
} catch (parseError) {
8461
return { error: parseError, version: null };
8562
}
@@ -109,8 +86,7 @@ function getMinor(version) {
10986
}
11087

11188
function getLatestVersion(callback) {
112-
const url =
113-
'https://selenium-release.storage.googleapis.com/?delimiter=/&prefix=';
89+
const url = 'https://selenium-release.storage.googleapis.com/';
11490

11591
function onFullVersionData(error, result) {
11692
if (error != null) {
@@ -120,19 +96,7 @@ function getLatestVersion(callback) {
12096
return callback(parsed.error, parsed.version);
12197
}
12298

123-
function onMinorVersionData(error, result) {
124-
if (error != null) {
125-
return callback(error);
126-
}
127-
const parsedMinor = parseSeleniumMinor(result);
128-
if (parsedMinor.error) {
129-
return callback(parsedMinor.error);
130-
}
131-
const prefixedUrl = `https://selenium-release.storage.googleapis.com/?delimiter=/&prefix=${parsedMinor.minorVersion}/`;
132-
return requestXml(prefixedUrl, onFullVersionData);
133-
}
134-
135-
return requestXml(url, onMinorVersionData);
99+
return requestXml(url, onFullVersionData);
136100
}
137101

138102
function getLatestDownloadInfo(callback) {

0 commit comments

Comments
 (0)