Skip to content

Commit 39d8fdd

Browse files
authored
fix: minBrowserVersion in SyncOption should be a number (#291)
1 parent 25b1c64 commit 39d8fdd

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

lib/storage-client.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
X64,
88
X86,
99
APPLE_ARM_SUFFIXES,
10+
convertToInt,
1011
} from './utils';
1112
import _ from 'lodash';
1213
import xpath from 'xpath';
@@ -296,9 +297,9 @@ class ChromedriverStorageClient {
296297
}
297298
}
298299

299-
if (_.isString(minBrowserVersion) && !Number.isNaN(minBrowserVersion)) {
300+
const minBrowserVersionInt = convertToInt(minBrowserVersion);
301+
if (minBrowserVersionInt !== null) {
300302
// Only select drivers that support the current browser whose major version number equals to `minBrowserVersion`
301-
const minBrowserVersionInt = parseInt(minBrowserVersion, 10);
302303
log.debug(
303304
`Selecting chromedrivers whose minimum supported browser version matches to ${minBrowserVersionInt}`
304305
);

lib/utils.js

+20
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,25 @@ function generateLogPrefix(obj, sessionId = null) {
147147
);
148148
}
149149

150+
/**
151+
* Converts the given object to an integer number if possible
152+
*
153+
* @param {any} value to be converted
154+
* @returns {number | null}
155+
*/
156+
function convertToInt(value) {
157+
switch (typeof value) {
158+
case 'number':
159+
return Number.isNaN(value) ? null : value;
160+
case 'string': {
161+
const parsedAsInt = parseInt(value, 10);
162+
return Number.isNaN(parsedAsInt) ? null : parsedAsInt;
163+
}
164+
default:
165+
return null;
166+
}
167+
}
168+
150169
export {
151170
getChromeVersion,
152171
getChromedriverDir,
@@ -164,4 +183,5 @@ export {
164183
X86,
165184
APPLE_ARM_SUFFIXES,
166185
generateLogPrefix,
186+
convertToInt,
167187
};

test/functional/storage-client-e2e-specs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('ChromedriverStorageClient', function () {
4141
});
4242
try {
4343
(await client.syncDrivers({
44-
minBrowserVersion: '44',
44+
minBrowserVersion: 44,
4545
})).length.should.be.greaterThan(0);
4646
(await fs.readdir(tmpRoot)).length.should.be.greaterThan(0);
4747
} finally {
@@ -56,7 +56,7 @@ describe('ChromedriverStorageClient', function () {
5656
});
5757
try {
5858
(await client.syncDrivers({
59-
minBrowserVersion: '74',
59+
minBrowserVersion: 74,
6060
})).length.should.be.greaterThan(0);
6161
(await fs.readdir(tmpRoot)).length.should.be.greaterThan(0);
6262
} finally {

test/unit/storage-client-specs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('ChromedriverStorageClient', function () {
165165
name: 'mac',
166166
arch: '64',
167167
}, {
168-
minBrowserVersion: '60',
168+
minBrowserVersion: 60,
169169
});
170170
selectedDrivers.should.eql([
171171
'76.0.3809.12/chromedriver_mac64.zip',
@@ -180,7 +180,7 @@ describe('ChromedriverStorageClient', function () {
180180
arch: '64',
181181
}, {
182182
versions: ['76.0.3809.12'],
183-
minBrowserVersion: '60',
183+
minBrowserVersion: 60,
184184
});
185185
selectedDrivers.should.eql([
186186
'76.0.3809.12/chromedriver_mac64.zip',

test/unit/utils-specs.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {convertToInt} from '../../lib/utils';
2+
import chai from 'chai';
3+
4+
chai.should();
5+
const should = chai.should();
6+
7+
describe('utils', function () {
8+
describe('convertToInt', function () {
9+
it('should parse a number', function () {
10+
convertToInt(0).should.eql(0);
11+
convertToInt(1).should.eql(1);
12+
convertToInt(100).should.eql(100);
13+
});
14+
it('should return null with NaN', function () {
15+
should.not.exist(convertToInt(NaN));
16+
});
17+
it('should parse a number string', function () {
18+
convertToInt('0').should.eql(0);
19+
convertToInt('1.1').should.eql(1);
20+
convertToInt('-123').should.eql(-123);
21+
});
22+
it('should return null if non numer string is given', function () {
23+
should.not.exist(convertToInt(''));
24+
should.not.exist(convertToInt('foo'));
25+
});
26+
it('should return null if unexpected type', function () {
27+
should.not.exist(convertToInt({}));
28+
should.not.exist(convertToInt(null));
29+
should.not.exist(convertToInt(true));
30+
});
31+
});
32+
});

0 commit comments

Comments
 (0)