@artilleryio/int-commons 2.0.1 → 2.0.2-18ad4ac

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/engine_util.js +18 -1
  2. package/package.json +5 -3
package/engine_util.js CHANGED
@@ -10,6 +10,7 @@ const deepForEach = require('deep-for-each');
10
10
  const espree = require('espree');
11
11
  const L = require('lodash');
12
12
  const vm = require('vm');
13
+ const ms = require('ms');
13
14
  const A = require('async');
14
15
  const { JSONPath: jsonpath } = require('jsonpath-plus');
15
16
  const cheerio = require('cheerio');
@@ -22,6 +23,8 @@ try {
22
23
  xmlCapture = null;
23
24
  }
24
25
 
26
+ // TODO Write tests
27
+
25
28
  module.exports = {
26
29
  createThink: createThink,
27
30
  createLoopWithCount: createLoopWithCount,
@@ -40,7 +43,15 @@ function createThink(requestSpec, opts) {
40
43
  let thinkspec = requestSpec.think;
41
44
 
42
45
  let f = function think(context, callback) {
43
- let thinktime = parseFloat(template(thinkspec, context)) * 1000;
46
+ let templatedThink = template(thinkspec, context);
47
+ let thinktime = Number.isInteger(L.toNumber(templatedThink))
48
+ ? ms(`${templatedThink}s`)
49
+ : ms(templatedThink);
50
+
51
+ if (typeof thinktime == 'undefined') {
52
+ throw new Error(`Invalid think time: ${templatedThink || thinkspec}`);
53
+ }
54
+
44
55
  if (requestSpec.jitter || opts.jitter) {
45
56
  thinktime = jitter(`${thinktime}:${requestSpec.jitter || opts.jitter}`);
46
57
  }
@@ -607,10 +618,16 @@ function extractRegExp(doc, expr, opts) {
607
618
  return '';
608
619
  }
609
620
 
621
+ // Captures named group (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group)
610
622
  if (group && match.groups) {
611
623
  return match.groups[group];
624
+ // Captures integer index defined group since those don't show up in match.groups
625
+ } else if (group && match[group]) {
626
+ return match[group];
627
+ // Defaults to first match if found and no group defined
612
628
  } else if (match[0]) {
613
629
  return match[0];
630
+ // If no match returns empty string
614
631
  } else {
615
632
  return '';
616
633
  }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@artilleryio/int-commons",
3
- "version": "2.0.1",
3
+ "version": "2.0.2-18ad4ac",
4
4
  "main": "./index.js",
5
+ "license": "MPL-2.0",
5
6
  "dependencies": {
6
7
  "async": "^2.6.4",
7
8
  "cheerio": "^1.0.0-rc.10",
@@ -9,10 +10,11 @@
9
10
  "deep-for-each": "^3.0.0",
10
11
  "espree": "^9.4.1",
11
12
  "jsonpath-plus": "^7.2.0",
12
- "lodash": "^4.17.19"
13
+ "lodash": "^4.17.19",
14
+ "ms": "^2.1.3"
13
15
  },
14
16
  "scripts": {
15
17
  "lint": "eslint --ext \".js,.ts,.tsx\" .",
16
18
  "lint-fix": "npm run lint -- --fix"
17
19
  }
18
- }
20
+ }