Fix timeout arguments conversion (#292)

This commit is contained in:
Mykola Mokhnach
2018-12-27 19:26:04 +01:00
committed by GitHub
parent 8d699e0359
commit ee17aef91c
2 changed files with 13 additions and 1 deletions
+2 -1
View File
@@ -71,7 +71,8 @@ class ProtocolConverter {
if (this.downstreamProtocol === MJSONWP && (!_.has(body, 'ms') || !_.has(body, 'type'))) {
const typeToJSONWP = (x) => x === 'pageLoad' ? 'page load' : x;
return _.toPairs(body)
.filter((pair) => !isNaN(parseFloat(pair[1])))
// Only transform the entry if ms value is a valid positive float number
.filter((pair) => /^\d+(?:[.,]\d*?)?$/.test(`${pair[1]}`))
.map((pair) => {
return {
type: typeToJSONWP(pair[0]),
@@ -23,6 +23,17 @@ describe('Protocol Converter', function () {
timeoutObjects.length.should.equal(1);
timeoutObjects[0].should.eql({type: 'script', ms: 100});
});
it('should ignore invalid entries while converting from W3C', function () {
converter.downstreamProtocol = MJSONWP;
let timeoutObjects = converter.getTimeoutRequestObjects({
script: 100,
sessionId: '5432a4f3-cd89-4781-8905-ea9d3150840c',
bar: -1,
baz: undefined,
});
timeoutObjects.length.should.equal(1);
timeoutObjects[0].should.eql({type: 'script', ms: 100});
});
it('should take multiple W3C timeouts and produce multiple MJSONWP compatible objects', function () {
converter.downstreamProtocol = MJSONWP;
let [scriptTimeout, pageLoadTimeout, implicitTimeout] = converter.getTimeoutRequestObjects({script: 100, pageLoad: 200, implicit: 300});