diff --git a/lib/consts.js b/lib/consts.js new file mode 100644 index 0000000..1a6573f --- /dev/null +++ b/lib/consts.js @@ -0,0 +1,7 @@ +const DEFAULT_POLL_VALUE = 60; +const POLL_LOWER_LIMIT = 20; + +module.exports = { + DEFAULT_POLL_VALUE, + POLL_LOWER_LIMIT +}; \ No newline at end of file diff --git a/lib/webpagetest.js b/lib/webpagetest.js index c593336..92f3427 100644 --- a/lib/webpagetest.js +++ b/lib/webpagetest.js @@ -15,6 +15,8 @@ var http = require("http"), server = require("./server"), mapping = require("./mapping"); +const { DEFAULT_POLL_VALUE, POLL_LOWER_LIMIT} = require("./consts"); + var reSpace = /\s/, reConnectivity = /^(?:Cable|DSL|3GSlow|3G|3GFast|4G|LTE|Edge|2G|Dial|FIOS|Native|custom)$/, @@ -474,7 +476,7 @@ function runTest(what, options, callback) { // poll results if (options.pollResults && !options.dryRun) { - options.pollResults = parseInt(options.pollResults * 1000, 10) || 5000; + options.pollResults = Math.max(POLL_LOWER_LIMIT, options.pollResults || DEFAULT_POLL_VALUE) * 1000; return api.call( this, @@ -537,7 +539,7 @@ function runTest(what, options, callback) { function runTestAndWait(what, options, callback) { delete options.pollResults; - options = Object.assign(options, { pollResults: 13 }); + options = Object.assign(options, { pollResults: DEFAULT_POLL_VALUE }); new Promise((resolve) => { let test = runTest.bind(this, what, options, callback); diff --git a/package.json b/package.json index 68daa4b..40a360c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpagetest", - "version": "0.7.5", + "version": "0.7.6", "description": "WebPageTest API wrapper for NodeJS", "author": "WebPageTest (http://github.com/WebPageTest)", "homepage": "http://github.com/WebPageTest/webpagetest-api",