From 8ba2ea4b3d320b301f09fb14a95a36ca095d4abc Mon Sep 17 00:00:00 2001 From: Johan Suleiko Allansson Date: Fri, 16 Aug 2024 11:34:18 +0200 Subject: [PATCH] add version of k6-utils including async check util --- lib/index.html | 2 +- lib/k6-utils/1.5.0/index.js | 2 ++ lib/k6-utils/1.5.0/index.js.map | 1 + supported.json | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 lib/k6-utils/1.5.0/index.js create mode 100644 lib/k6-utils/1.5.0/index.js.map diff --git a/lib/index.html b/lib/index.html index b6925f1..e2174f3 100644 --- a/lib/index.html +++ b/lib/index.html @@ -576,7 +576,7 @@

Available libs

k6-utils - 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0 + 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0 https://grafana.com/docs/k6/latest/javascript-api/jslib/utils k6-summary diff --git a/lib/k6-utils/1.5.0/index.js b/lib/k6-utils/1.5.0/index.js new file mode 100644 index 0000000..a9c3079 --- /dev/null +++ b/lib/k6-utils/1.5.0/index.js @@ -0,0 +1,2 @@ +(()=>{"use strict";var e={184:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.check=function(e,t,r){var a=Object.entries(t).map((function(t){var a=t[0],o=t[1];function i(e){return n.add(e?1:0,Object.assign({},r,{check:a})),e}if("function"==typeof o){var u=o(e);return u instanceof Promise?u.then(i):i(u)}return o instanceof Promise?o.then(i):i(o)}));if(a.some((function(e){return e instanceof Promise})))return Promise.all(a).then((function(e){return e.every(Boolean)}));return a.every(Boolean)};var n=new(r(610).Rate)("checks")},664:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.parseDuration=o,t.getCurrentStageIndex=u,t.tagWithCurrentStageIndex=function(){a.default.vu.tags.stage=u()},t.tagWithCurrentStageProfile=function(){a.default.vu.tags.stage_profile=function(){var e=u();if(e<1)return"ramp-up";var t=a.default.test.options.scenarios[a.default.scenario.name].stages,r=t[e],n=t[e-1];return r.target>n.target?"ramp-up":n.target==r.target?"steady":"ramp-down"}()};var a=n(r(744));function o(e){if(null==e||e.length<1)throw new Error("str is empty");for(var t=0,r="",n={},a=0;a0&&(t+=parseFloat(r,10)),t}function i(e){return e>="0"&&e<="9"}function u(){var e=a.default.test.options.scenarios[a.default.scenario.name];if(null==e)throw new Error("the exec.test.options object doesn't contain the current scenario ".concat(a.default.scenario.name));if(null==e.stages)throw new Error("only ramping-vus or ramping-arravial-rate supports stages, it is not possible to get a stage index on other executors.");if(e.stages.length<1)throw new Error("the current scenario ".concat(e.name," doesn't contain any stage"));for(var t=0,r=new Date-a.default.scenario.startTime,n=0;n{Object.defineProperty(t,"__esModule",{value:!0}),t.uuidv4=function(e){void 0===e&&(e=!1);return e?function(){for(var e=[],t=0;t<256;++t)e.push((t+256).toString(16).slice(1));var r=new Uint8Array((0,n.randomBytes)(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,(e[r[0]]+e[r[1]]+e[r[2]]+e[r[3]]+"-"+e[r[4]]+e[r[5]]+"-"+e[r[6]]+e[r[7]]+"-"+e[r[8]]+e[r[9]]+"-"+e[r[10]]+e[r[11]]+e[r[12]]+e[r[13]]+e[r[14]]+e[r[15]]).toLowerCase()}():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},t.randomIntBetween=function(e,t){return Math.floor(Math.random()*(t-e+1)+e)},t.randomItem=function(e){return e[Math.floor(Math.random()*e.length)]},t.randomString=function(e,t){void 0===t&&(t="abcdefghijklmnopqrstuvwxyz");var r="";for(;e--;)r+=t[Math.random()*t.length|0];return r},t.findBetween=function(e,t,r,n){void 0===n&&(n=!1);var a,o=[],i=0;for(;-1!=(a=e.indexOf(t))&&(a+=t.length,-1!=(i=e.indexOf(r,a)));){var u=e.substring(a,i);if(!n)return u;o.push(u),e=e.substring(i+r.length)}return o.length?o:null},t.normalDistributionStages=function(e,t,r){void 0===r&&(r=10);function n(e,t,r){return Math.exp(-.5*Math.pow((r-e)/t,2))/(t*Math.sqrt(2*Math.PI))}for(var a=new Array(r+2).fill(0),o=new Array(r+2).fill(Math.ceil(t/6)),i=[],u=0;u<=r;u++)a[u]=n(0,1,4*u/r-2);for(var s=Math.max.apply(Math,a),c=a.map((function(t){return Math.round(t*e/s)})),f=1;f<=r;f++)o[f]=Math.ceil(4*t/(6*r));for(var l=0;l<=r+1;l++)i.push({duration:"".concat(o[l],"s"),target:c[l]});return i};var n=r(400)},400:e=>{e.exports=require("k6/crypto")},744:e=>{e.exports=require("k6/execution")},610:e=>{e.exports=require("k6/metrics")}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}var n={};(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.uuidv4=e.randomString=e.randomItem=e.randomIntBetween=e.normalDistributionStages=e.findBetween=e.tagWithCurrentStageProfile=e.tagWithCurrentStageIndex=e.getCurrentStageIndex=e.parseDuration=e.check=void 0;var t=r(664);Object.defineProperty(e,"parseDuration",{enumerable:!0,get:function(){return t.parseDuration}}),Object.defineProperty(e,"getCurrentStageIndex",{enumerable:!0,get:function(){return t.getCurrentStageIndex}}),Object.defineProperty(e,"tagWithCurrentStageIndex",{enumerable:!0,get:function(){return t.tagWithCurrentStageIndex}}),Object.defineProperty(e,"tagWithCurrentStageProfile",{enumerable:!0,get:function(){return t.tagWithCurrentStageProfile}});var a=r(599);Object.defineProperty(e,"findBetween",{enumerable:!0,get:function(){return a.findBetween}}),Object.defineProperty(e,"normalDistributionStages",{enumerable:!0,get:function(){return a.normalDistributionStages}}),Object.defineProperty(e,"randomIntBetween",{enumerable:!0,get:function(){return a.randomIntBetween}}),Object.defineProperty(e,"randomItem",{enumerable:!0,get:function(){return a.randomItem}}),Object.defineProperty(e,"randomString",{enumerable:!0,get:function(){return a.randomString}}),Object.defineProperty(e,"uuidv4",{enumerable:!0,get:function(){return a.uuidv4}});var o=r(184);Object.defineProperty(e,"check",{enumerable:!0,get:function(){return o.check}})})();var a=exports;for(var o in n)a[o]=n[o];n.__esModule&&Object.defineProperty(a,"__esModule",{value:!0})})(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/k6-utils/1.5.0/index.js.map b/lib/k6-utils/1.5.0/index.js.map new file mode 100644 index 0000000..e36ea0d --- /dev/null +++ b/lib/k6-utils/1.5.0/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","mappings":"wCACAA,OAAOC,eAAeC,EAAS,aAAc,CAAEC,OAAO,IACtDD,EAAQE,MAGR,SAAeD,EAAOE,EAAUC,GAC5B,IAAIC,EAAUP,OAAOQ,QAAQH,GAAUI,KAAI,SAAUC,GACjD,IAAIC,EAAMD,EAAG,GAAIE,EAAUF,EAAG,GAC9B,SAASG,EAAaV,GAIlB,OAHAW,EAAUC,IAAIZ,EAAQ,EAAI,EAAGH,OAAOgB,OAAO,GAAIV,EAAM,CACjDF,MAAOO,KAEJR,EAEX,GAAuB,mBAAZS,EAAwB,CAC/B,IAAIK,EAASL,EAAQT,GACrB,OAAIc,aAAkBC,QACXD,EAAOE,KAAKN,GAEhBA,EAAaI,GAExB,OAAIL,aAAmBM,QACZN,EAAQO,KAAKN,GAEjBA,EAAaD,MAExB,GAAIL,EAAQa,MAAK,SAAUH,GAAU,OAAOA,aAAkBC,WAC1D,OAAOA,QAAQG,IAAId,GAASY,MAAK,SAAUZ,GAAW,OAAOA,EAAQe,MAAMC,YAE/E,OAAOhB,EAAQe,MAAMC,UA1BzB,IACIT,EAAY,IADA,EAAQ,KACMU,MAAK,W,oBCHnC,IAAIC,EAAmBC,MAAQA,KAAKD,iBAAoB,SAAUE,GAC9D,OAAQA,GAAOA,EAAIC,WAAcD,EAAM,CAAE,QAAWA,IAExD3B,OAAOC,eAAeC,EAAS,aAAc,CAAEC,OA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SAAU,CAAEqI,YAAY,EAAMC,IAAK,WAAc,OAAOC,EAAWvE,UAClG,IAAIwE,EAAa,EAAQ,KACzB1I,OAAOC,eAAeC,EAAS,QAAS,CAAEqI,YAAY,EAAMC,IAAK,WAAc,OAAOE,EAAWtI,U","sources":["webpack://k6-jslib-utils/./src/check.ts","webpack://k6-jslib-utils/./src/stages.js","webpack://k6-jslib-utils/./src/utils.js","webpack://k6-jslib-utils/external commonjs \"k6/crypto\"","webpack://k6-jslib-utils/external commonjs \"k6/execution\"","webpack://k6-jslib-utils/external commonjs \"k6/metrics\"","webpack://k6-jslib-utils/webpack/bootstrap","webpack://k6-jslib-utils/./src/index.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.check = check;\nvar metrics_1 = require(\"k6/metrics\");\nvar checkRate = new metrics_1.Rate('checks');\nfunction check(value, checkers, tags) {\n var results = Object.entries(checkers).map(function (_a) {\n var key = _a[0], checker = _a[1];\n function reportResult(value) {\n checkRate.add(value ? 1 : 0, Object.assign({}, tags, {\n check: key,\n }));\n return value;\n }\n if (typeof checker === 'function') {\n var result = checker(value);\n if (result instanceof Promise) {\n return result.then(reportResult);\n }\n return reportResult(result);\n }\n if (checker instanceof Promise) {\n return checker.then(reportResult);\n }\n return reportResult(checker);\n });\n if (results.some(function (result) { return result instanceof Promise; })) {\n return Promise.all(results).then(function (results) { return results.every(Boolean); });\n }\n return results.every(Boolean);\n}\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.parseDuration = parseDuration;\nexports.getCurrentStageIndex = getCurrentStageIndex;\nexports.tagWithCurrentStageIndex = tagWithCurrentStageIndex;\nexports.tagWithCurrentStageProfile = tagWithCurrentStageProfile;\nvar execution_1 = __importDefault(require(\"k6/execution\"));\n// parseDuration parses the provided string as an Integer number\n// in millisecond precision\nfunction parseDuration(str) {\n if (str == null || str.length < 1) {\n throw new Error('str is empty');\n }\n // the sum in millisecond of the parsed duration\n var d = 0;\n // current contains the partial seen number\n // it's reset when a time unit is found\n var current = '';\n // it tracks the seen time units\n // and it denies eventual duplicated\n var seen = {};\n for (var i = 0; i < str.length; i++) {\n // append the current char if it's a number or a decimal separator\n if (isNumber(str[i]) || str[i] == '.') {\n current += str[i];\n }\n // return if the next char is not a time unit\n if (str[i + 1] == null || isNumber(str[i + 1]) || str[i + 1] == '.') {\n continue;\n }\n var v = parseFloat(current, 10);\n var next = str[i + 1];\n switch (next) {\n case 'd':\n d += v * 24 * 60 * 60 * 1000;\n break;\n case 'h':\n d += v * 60 * 60 * 1000;\n break;\n case 'm':\n if (i + 2 < str.length && str[i + 2] == 's') {\n // millisecond is the maximum precision\n // truncate eventual decimal\n d += Math.trunc(v);\n i++;\n next = 'ms';\n }\n else {\n d += v * 60 * 1000;\n }\n break;\n case 's':\n d += v * 1000;\n break;\n default:\n throw new Error(\"\".concat(next, \" is an unsupported time unit\"));\n }\n if (seen[next]) {\n throw new Error(\"\".concat(next, \" time unit is provided multiple times\"));\n }\n seen[next] = true;\n i++;\n current = '';\n }\n // flush in case no time unit has been provided\n // for the latest group\n if (current.length > 0) {\n d += parseFloat(current, 10);\n }\n return d;\n}\n// isNumber return true if the c character is a number\nfunction isNumber(c) {\n return c >= '0' && c <= '9';\n}\n// getCurrentStageIndex returns the computed index of the running stage.\nfunction getCurrentStageIndex() {\n var scenario = execution_1.default.test.options.scenarios[execution_1.default.scenario.name];\n if (scenario == null) {\n throw new Error(\"the exec.test.options object doesn't contain the current scenario \".concat(execution_1.default.scenario.name));\n }\n if (scenario.stages == null) {\n throw new Error(\"only ramping-vus or ramping-arravial-rate supports stages, it is not possible to get a stage index on other executors.\");\n }\n if (scenario.stages.length < 1) {\n throw new Error(\"the current scenario \".concat(scenario.name, \" doesn't contain any stage\"));\n }\n var sum = 0;\n var elapsed = new Date() - execution_1.default.scenario.startTime;\n for (var i = 0; i < scenario.stages.length; i++) {\n sum += parseDuration(scenario.stages[i].duration);\n if (elapsed < sum) {\n return i;\n }\n }\n return scenario.stages.length - 1;\n}\n// tagWithCurrentStageIndex adds a tag with a `stage` key\n// and the index of the current running stage as value.\nfunction tagWithCurrentStageIndex() {\n execution_1.default.vu.tags['stage'] = getCurrentStageIndex();\n}\n// tagWithCurrentStageProfile adds a tag with a `stage` key\n// and the profile (ramp-up, steady or ramp-down) computed\n// from the current running stage.\nfunction tagWithCurrentStageProfile() {\n //ramp-up when previous.target < current.target\n //ramp-down when previous.target > current.target\n //steady when prevuious.target = current.target\n var getStageProfile = function () {\n var currentIndex = getCurrentStageIndex();\n if (currentIndex < 1) {\n return 'ramp-up';\n }\n var stages = execution_1.default.test.options.scenarios[execution_1.default.scenario.name].stages;\n var current = stages[currentIndex];\n var previous = stages[currentIndex - 1];\n if (current.target > previous.target) {\n return 'ramp-up';\n }\n if (previous.target == current.target) {\n return 'steady';\n }\n return 'ramp-down';\n };\n execution_1.default.vu.tags['stage_profile'] = getStageProfile();\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.uuidv4 = uuidv4;\nexports.randomIntBetween = randomIntBetween;\nexports.randomItem = randomItem;\nexports.randomString = randomString;\nexports.findBetween = findBetween;\nexports.normalDistributionStages = normalDistributionStages;\nvar crypto_1 = require(\"k6/crypto\");\n/**\n * Produces a Universal Unique Identifier version 4\n *\n * @param {boolean} secure - whether a cryptographically secure generation function should be used\n * @returns {String} - 16 characters hexadecimal representation of the UUID v4\n */\nfunction uuidv4(secure) {\n if (secure === void 0) { secure = false; }\n return secure ? secureUUIDv4() : insecureUUIDv4();\n}\nfunction randomIntBetween(min, max) {\n // min and max included\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\nfunction randomItem(arrayOfItems) {\n return arrayOfItems[Math.floor(Math.random() * arrayOfItems.length)];\n}\nfunction randomString(length, charset) {\n if (charset === void 0) { charset = 'abcdefghijklmnopqrstuvwxyz'; }\n var res = '';\n while (length--)\n res += charset[(Math.random() * charset.length) | 0];\n return res;\n}\nfunction findBetween(content, left, right, repeat) {\n if (repeat === void 0) { repeat = false; }\n var extracted = [];\n var doSearch = true;\n var start, end = 0;\n while (doSearch) {\n start = content.indexOf(left);\n if (start == -1) {\n break; // no more matches\n }\n start += left.length;\n end = content.indexOf(right, start);\n if (end == -1) {\n break; // no more matches\n }\n var extractedContent = content.substring(start, end);\n // stop here if only extracting one match (default behavior)\n if (!repeat) {\n return extractedContent;\n }\n // otherwise, add it to the array\n extracted.push(extractedContent);\n // update the \"cursor\" position to the end of the previous match\n content = content.substring(end + right.length);\n }\n return extracted.length ? extracted : null; // return all matches as an array or null\n}\nfunction normalDistributionStages(maxVus, durationSeconds, numberOfStages) {\n if (numberOfStages === void 0) { numberOfStages = 10; }\n function normalDensity(mean, scale, x) {\n return (Math.exp((-1 / 2) * Math.pow((x - mean) / scale, 2)) / (scale * Math.sqrt(2 * Math.PI)));\n }\n var mean = 0;\n var scale = 1;\n var curve = new Array(numberOfStages + 2).fill(0);\n var durations = new Array(numberOfStages + 2).fill(Math.ceil(durationSeconds / 6));\n var k6stages = [];\n for (var i = 0; i <= numberOfStages; i++) {\n curve[i] = normalDensity(mean, scale, -2 * scale + (4 * scale * i) / numberOfStages);\n }\n var peakDistribution = Math.max.apply(Math, curve);\n var vus = curve.map(function (x) { return Math.round((x * maxVus) / peakDistribution); });\n for (var j = 1; j <= numberOfStages; j++) {\n durations[j] = Math.ceil((4 * durationSeconds) / (6 * numberOfStages));\n }\n for (var k = 0; k <= numberOfStages + 1; k++) {\n k6stages.push({ duration: \"\".concat(durations[k], \"s\"), target: vus[k] });\n }\n return k6stages;\n}\n/**\n * Fast UUID v4 producer\n *\n * Note that this function does not produce cryptographically\n * secure UUIDs. If you need safe UUIDs, use the secureUUIDv4\n * implementation instead.\n *\n * @returns {String} - 16 characters hexadecimal representation of the UUID v4\n */\nfunction insecureUUIDv4() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n var r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n/**\n * Cryptographically secure UUID v4 producer\n *\n * Note that this implementation involves a computation\n * overhead.\n *\n * @returns {String} - 16 characters hexadecimal representation of the UUID v4\n */\nfunction secureUUIDv4() {\n /**\n * bytes conversion table used to convert UUIDs bytes\n * to string form.\n */\n var byteToHex = [];\n for (var i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n }\n /**\n * produce 16 random bytes, and set UUID v4's specific\n * version and `clock_seq_hi_and_reserved` bits.\n */\n var rnds = new Uint8Array((0, crypto_1.randomBytes)(16));\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n /**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n return (byteToHex[rnds[0]] +\n byteToHex[rnds[1]] +\n byteToHex[rnds[2]] +\n byteToHex[rnds[3]] +\n '-' +\n byteToHex[rnds[4]] +\n byteToHex[rnds[5]] +\n '-' +\n byteToHex[rnds[6]] +\n byteToHex[rnds[7]] +\n '-' +\n byteToHex[rnds[8]] +\n byteToHex[rnds[9]] +\n '-' +\n byteToHex[rnds[10]] +\n byteToHex[rnds[11]] +\n byteToHex[rnds[12]] +\n byteToHex[rnds[13]] +\n byteToHex[rnds[14]] +\n byteToHex[rnds[15]]).toLowerCase();\n}\n","module.exports = require(\"k6/crypto\");","module.exports = require(\"k6/execution\");","module.exports = require(\"k6/metrics\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.uuidv4 = exports.randomString = exports.randomItem = exports.randomIntBetween = exports.normalDistributionStages = exports.findBetween = exports.tagWithCurrentStageProfile = exports.tagWithCurrentStageIndex = exports.getCurrentStageIndex = exports.parseDuration = exports.check = void 0;\nvar stages_js_1 = require(\"./stages.js\");\nObject.defineProperty(exports, \"parseDuration\", { enumerable: true, get: function () { return stages_js_1.parseDuration; } });\nObject.defineProperty(exports, \"getCurrentStageIndex\", { enumerable: true, get: function () { return stages_js_1.getCurrentStageIndex; } });\nObject.defineProperty(exports, \"tagWithCurrentStageIndex\", { enumerable: true, get: function () { return stages_js_1.tagWithCurrentStageIndex; } });\nObject.defineProperty(exports, \"tagWithCurrentStageProfile\", { enumerable: true, get: function () { return stages_js_1.tagWithCurrentStageProfile; } });\nvar utils_js_1 = require(\"./utils.js\");\nObject.defineProperty(exports, \"findBetween\", { enumerable: true, get: function () { return utils_js_1.findBetween; } });\nObject.defineProperty(exports, \"normalDistributionStages\", { enumerable: true, get: function () { return utils_js_1.normalDistributionStages; } });\nObject.defineProperty(exports, \"randomIntBetween\", { enumerable: true, get: function () { return utils_js_1.randomIntBetween; } });\nObject.defineProperty(exports, \"randomItem\", { enumerable: true, get: function () { return utils_js_1.randomItem; } });\nObject.defineProperty(exports, \"randomString\", { enumerable: true, get: function () { return utils_js_1.randomString; } });\nObject.defineProperty(exports, \"uuidv4\", { enumerable: true, get: function () { return utils_js_1.uuidv4; } });\nvar check_ts_1 = require(\"./check.ts\");\nObject.defineProperty(exports, \"check\", { enumerable: true, get: function () { return check_ts_1.check; } });\n"],"names":["Object","defineProperty","exports","value","check","checkers","tags","results","entries","map","_a","key","checker","reportResult","checkRate","add","assign","result","Promise","then","some","all","every","Boolean","Rate","__importDefault","this","mod","__esModule","parseDuration","getCurrentStageIndex","tagWithCurrentStageIndex","execution_1","default","vu","tagWithCurrentStageProfile","currentIndex","stages","test","options","scenarios","scenario","name","current","previous","target","getStageProfile","str","length","Error","d","seen","i","isNumber","v","parseFloat","next","Math","trunc","concat","c","sum","elapsed","Date","startTime","duration","uuidv4","secure","byteToHex","push","toString","slice","rnds","Uint8Array","crypto_1","randomBytes","toLowerCase","secureUUIDv4","replace","r","random","randomIntBetween","min","max","floor","randomItem","arrayOfItems","randomString","charset","res","findBetween","content","left","right","repeat","start","extracted","end","indexOf","extractedContent","substring","normalDistributionStages","maxVus","durationSeconds","numberOfStages","normalDensity","mean","scale","x","exp","pow","sqrt","PI","curve","Array","fill","durations","ceil","k6stages","peakDistribution","apply","vus","round","j","k","module","require","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","call","stages_js_1","enumerable","get","utils_js_1","check_ts_1"],"sourceRoot":""} \ No newline at end of file diff --git a/supported.json b/supported.json index 43efb47..fc00a72 100644 --- a/supported.json +++ b/supported.json @@ -1,6 +1,6 @@ { "k6-utils": { - "versions": ["1.0.0", "1.1.0", "1.2.0", "1.3.0", "1.4.0"], + "versions": ["1.0.0", "1.1.0", "1.2.0", "1.3.0", "1.4.0", "1.5.0"], "docs-url": "https://grafana.com/docs/k6/latest/javascript-api/jslib/utils" }, "k6-summary": {