@artilleryio/int-core 2.0.6 → 2.0.8

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.
package/index.js CHANGED
@@ -20,7 +20,8 @@ async function updateGlobalObject(opts = {}) {
20
20
 
21
21
  global.artillery.util = global.artillery.util || {};
22
22
 
23
- global.artillery.util.template = require('@artilleryio/int-commons').engine_util.template;
23
+ global.artillery.util.template =
24
+ require('@artilleryio/int-commons').engine_util.template;
24
25
 
25
26
  global.artillery.plugins = global.artillery.plugins || [];
26
27
 
@@ -36,8 +37,7 @@ async function updateGlobalObject(opts = {}) {
36
37
  if (!global.artillery.hasOwnProperty('globalEvents')) {
37
38
  Object.defineProperty(global.artillery, 'globalEvents', {
38
39
  value: new EventEmitter()
39
- })
40
-
40
+ });
41
41
  }
42
42
 
43
43
  global.artillery.__SSMS = require('./lib/ssms').SSMS;
@@ -50,23 +50,30 @@ async function updateGlobalObject(opts = {}) {
50
50
  set(code) {
51
51
  global.artillery._exitCode = code;
52
52
  if (typeof global.artillery._workerThreadSend === 'function') {
53
- global.artillery._workerThreadSend({ event: 'setSuggestedExitCode', code: code });
53
+ global.artillery._workerThreadSend({
54
+ event: 'setSuggestedExitCode',
55
+ code: code
56
+ });
54
57
  }
55
58
  }
56
59
  });
57
60
  }
58
61
 
59
- global.artillery.logger = global.artillery.logger || function (opts) {
60
- return {
61
- log: (...args) => {
62
- global.artillery.globalEvents.emit('log', opts, ...args);
63
- }
62
+ global.artillery.logger =
63
+ global.artillery.logger ||
64
+ function (opts) {
65
+ return {
66
+ log: (...args) => {
67
+ global.artillery.globalEvents.emit('log', opts, ...args);
68
+ }
69
+ };
64
70
  };
65
- };
66
71
 
67
- global.artillery.log = global.artillery.log || function (...args) {
68
- global.artillery.globalEvents.emit('log', {}, ...args);
69
- };
72
+ global.artillery.log =
73
+ global.artillery.log ||
74
+ function (...args) {
75
+ global.artillery.globalEvents.emit('log', {}, ...args);
76
+ };
70
77
 
71
78
  if (opts.version) {
72
79
  global.artillery.version = opts.version;
@@ -85,9 +85,9 @@ function HttpEngine(script) {
85
85
  this.config.http = {};
86
86
  }
87
87
 
88
- if(typeof this.config.http.cookieJarOptions === 'undefined') {
88
+ if (typeof this.config.http.cookieJarOptions === 'undefined') {
89
89
  this.config.http.cookieJarOptions = {};
90
- };
90
+ }
91
91
 
92
92
  // If config.http.pool is set, create & reuse agents for all requests (with
93
93
  // max sockets set). That's what we're done here.
@@ -507,7 +507,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
507
507
  debugResponse(JSON.stringify(body, null, 2));
508
508
 
509
509
  // capture/match/response hooks run only for last request in a task
510
- if(!isLast) {
510
+ if (!isLast) {
511
511
  return done(null, context);
512
512
  }
513
513
 
@@ -612,10 +612,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
612
612
 
613
613
  if (haveFailedMatches || haveFailedCaptures) {
614
614
  // FIXME: This means only one error in the report even if multiple captures failed for the same request.
615
- return done(
616
- new Error('Failed capture or match'),
617
- context
618
- );
615
+ return done(new Error('Failed capture or match'), context);
619
616
  }
620
617
  return done(null, context);
621
618
  }
@@ -656,6 +653,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
656
653
  requestParams.retry = 0; // disable retries - ignored when using streams
657
654
 
658
655
  const uuid = crypto.randomUUID();
656
+ let totalDownloaded = 0;
659
657
  request(requestParams)
660
658
  .on('request', function (req) {
661
659
  ee.emit('trace:http:request', requestParams, uuid);
@@ -664,6 +662,9 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
664
662
  ee.emit('counter', 'http.requests', 1);
665
663
  ee.emit('rate', 'http.request_rate');
666
664
  req.on('response', function (res) {
665
+ res.on('end', () => {
666
+ ee.emit('counter', 'http.downloaded_bytes', totalDownloaded);
667
+ });
667
668
  ee.emit('trace:http:response', res, uuid);
668
669
  self._handleResponse(
669
670
  requestParams,
@@ -674,7 +675,9 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
674
675
  callback
675
676
  );
676
677
  });
677
-
678
+ })
679
+ .on('downloadProgress', (progress) => {
680
+ totalDownloaded = progress.total;
678
681
  })
679
682
  .on('error', function (err, body, res) {
680
683
  ee.emit('trace:http:error', err, uuid);
@@ -730,7 +733,9 @@ HttpEngine.prototype._handleResponse = function (
730
733
  try {
731
734
  context._jar.setCookieSync(cookieString, url);
732
735
  } catch (err) {
733
- debug(`Could not parse cookieString "${cookieString}" from response header, skipping it`);
736
+ debug(
737
+ `Could not parse cookieString "${cookieString}" from response header, skipping it`
738
+ );
734
739
  debug(err);
735
740
  ee.emit('error', 'cookie_parse_error_invalid_cookie');
736
741
  }
@@ -768,8 +773,8 @@ HttpEngine.prototype._handleResponse = function (
768
773
 
769
774
  if (responseProcessor) {
770
775
  responseProcessor(isLastRequest, res, body, (processResponseErr) => {
771
- // capture/match returned an error object, or a hook function returned
772
- // with an error
776
+ // capture/match returned an error object, or a hook function returned
777
+ // with an error
773
778
  if (processResponseErr) {
774
779
  return callback(processResponseErr, context);
775
780
  }
@@ -791,15 +796,23 @@ function lastRequest(res, requestParams) {
791
796
  // - 3xx response and not following redirects
792
797
  // - not a 3xx response
793
798
 
794
- return ((res.statusCode >= 300 && res.statusCode < 400 && !requestParams.followRedirect) ||
795
- (res.statusCode < 300 || res.statusCode >= 400))
799
+ return (
800
+ (res.statusCode >= 300 &&
801
+ res.statusCode < 400 &&
802
+ !requestParams.followRedirect) ||
803
+ res.statusCode < 300 ||
804
+ res.statusCode >= 400
805
+ );
796
806
  }
797
807
 
798
808
  HttpEngine.prototype.setInitialContext = function (initialContext) {
799
809
  initialContext._successCount = 0;
800
810
 
801
811
  initialContext._defaultStrictCapture = this.config.defaults.strictCapture;
802
- initialContext._jar = new tough.CookieJar(null, this.config.http.cookieJarOptions);
812
+ initialContext._jar = new tough.CookieJar(
813
+ null,
814
+ this.config.http.cookieJarOptions
815
+ );
803
816
 
804
817
  initialContext._enableCookieJar = false;
805
818
  // If a default cookie is set, we will use the jar straightaway:
package/lib/readers.js CHANGED
@@ -11,9 +11,14 @@ module.exports = createReader;
11
11
  function createReader(order, spec) {
12
12
  if (order === 'sequence') {
13
13
  return createSequencedReader();
14
- } else if (typeof order === 'undefined' && (typeof spec?.name !== 'undefined') && spec?.loadAll === true) {
14
+ } else if (
15
+ typeof order === 'undefined' &&
16
+ typeof spec?.name !== 'undefined' &&
17
+ spec?.loadAll === true
18
+ ) {
15
19
  return createEverythingReader(spec);
16
- } else { // random
20
+ } else {
21
+ // random
17
22
  return createRandomReader();
18
23
  }
19
24
  }
@@ -42,10 +47,10 @@ function createEverythingReader(spec) {
42
47
  if (spec.fields?.length > 0) {
43
48
  for (const row of data) {
44
49
  let o = {};
45
- for(let i = 0; i < spec.fields.length; i++) {
46
- const fieldName = spec.fields[i];
47
- o[fieldName] = row[i];
48
- }
50
+ for (let i = 0; i < spec.fields.length; i++) {
51
+ const fieldName = spec.fields[i];
52
+ o[fieldName] = row[i];
53
+ }
49
54
  parsedData.push(o);
50
55
  }
51
56
  } else {
package/lib/runner.js CHANGED
@@ -103,7 +103,10 @@ function prepareScript(script, payload) {
103
103
  runnableScript.config.payload = [
104
104
  {
105
105
  fields: runnableScript.config.payload.fields,
106
- reader: createReader(runnableScript.config.payload.order, runnableScript.config.payload),
106
+ reader: createReader(
107
+ runnableScript.config.payload.order,
108
+ runnableScript.config.payload
109
+ ),
107
110
  data: payload
108
111
  }
109
112
  ];
@@ -386,7 +389,8 @@ function createContext(script, contextVars) {
386
389
  {
387
390
  target: script.config.target,
388
391
  $environment: script._environment,
389
- $processEnvironment: process.env
392
+ $processEnvironment: process.env, // TODO: deprecate
393
+ $env: process.env
390
394
  },
391
395
  contextVars || {}
392
396
  ),
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "main": "./index.js",
5
5
  "dependencies": {
6
6
  "@artilleryio/int-commons": "latest",
7
- "@artilleryio/sketches-js": "^1.0.4",
7
+ "@artilleryio/sketches-js": "^2.1.0",
8
8
  "agentkeepalive": "^4.1.0",
9
9
  "arrivals": "^2.1.2",
10
10
  "async": "^2.6.4",
@@ -26,7 +26,6 @@
26
26
  "https-proxy-agent": "^5.0.0",
27
27
  "lodash": "^4.17.19",
28
28
  "proxy": "^1.0.2",
29
- "socket.io": "^3.1.2",
30
29
  "socket.io-client": "^4.5.1",
31
30
  "socketio-wildcard": "^2.0.0",
32
31
  "tough-cookie": "^4.0.0",
@@ -46,6 +45,7 @@
46
45
  "nock": "^11.8.2",
47
46
  "rewiremock": "^3.14.3",
48
47
  "sinon": "^4.5.0",
48
+ "socket.io": "^4.7.1",
49
49
  "tap": "15.2.3"
50
50
  }
51
51
  }