@artilleryio/int-core 2.24.0 → 2.25.0-8732536

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.
@@ -4,7 +4,6 @@
4
4
 
5
5
  const async = require('async');
6
6
  const _ = require('lodash');
7
- const request = require('got');
8
7
  const tough = require('tough-cookie');
9
8
  const debug = require('debug')('http');
10
9
  const debugRequests = require('debug')('http:request');
@@ -30,6 +29,30 @@ const crypto = require('node:crypto');
30
29
 
31
30
  module.exports = HttpEngine;
32
31
 
32
+ const GOT_OPTION_NAMES = [
33
+ 'url',
34
+ 'searchParams',
35
+ 'method',
36
+ 'headers',
37
+ 'body',
38
+ 'json',
39
+ 'form',
40
+ 'allowGetBody',
41
+ 'timeout',
42
+ 'retry',
43
+ 'encoding',
44
+ 'cookieJar',
45
+ 'followRedirect',
46
+ 'maxRedirects',
47
+ 'decompress',
48
+ 'http2',
49
+ 'agent',
50
+ 'username',
51
+ 'password',
52
+ 'https',
53
+ 'throwHttpErrors'
54
+ ];
55
+
33
56
  const DEFAULT_AGENT_OPTIONS = {
34
57
  keepAlive: true,
35
58
  keepAliveMsec: 1000
@@ -126,6 +149,10 @@ function HttpEngine(script) {
126
149
  }
127
150
  }
128
151
 
152
+ HttpEngine.prototype.init = async function () {
153
+ this.request = (await import('got')).default;
154
+ };
155
+
129
156
  HttpEngine.prototype.createScenario = function (scenarioSpec, ee) {
130
157
  ensurePropertyIsAList(scenarioSpec, 'beforeRequest');
131
158
  ensurePropertyIsAList(scenarioSpec, 'afterResponse');
@@ -274,7 +301,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
274
301
  const requestParams = _.extend(_.clone(params), {
275
302
  url: maybePrependBase(params.url || params.uri, config), // *NOT* templating here
276
303
  method: method,
277
- timeout: timeout * 1000,
304
+ timeout: timeout,
278
305
  uuid: crypto.randomUUID()
279
306
  });
280
307
 
@@ -683,10 +710,14 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
683
710
  );
684
711
  }
685
712
 
686
- requestParams.retry = 0; // disable retries - ignored when using streams
713
+ requestParams.retry = { limit: 0 }; // disable retries - ignored when using streams
714
+ // Convert scalar seconds to Got v14 timeout object right before request
715
+ const gotOptions = _.pick(requestParams, GOT_OPTION_NAMES);
716
+ gotOptions.timeout = { response: requestParams.timeout * 1000 };
687
717
 
688
718
  let totalDownloaded = 0;
689
- request(_.omit(requestParams, ['uuid']))
719
+ self
720
+ .request(gotOptions)
690
721
  .on('request', (req) => {
691
722
  ee.emit('trace:http:request', requestParams, requestParams.uuid);
692
723
 
@@ -937,10 +968,16 @@ HttpEngine.prototype.compile = function compile(tasks, _scenarioSpec, ee) {
937
968
  context = await promisify(task)(context);
938
969
  } catch (taskErr) {
939
970
  ee.emit('error', taskErr.code || taskErr.message);
940
- return callback(taskErr, context); // calling back for now for existing client code
971
+ if (callback) {
972
+ return callback(taskErr, context);
973
+ }
974
+ throw taskErr;
941
975
  }
942
976
  }
943
- return callback(null, context);
977
+ if (callback) {
978
+ return callback(null, context);
979
+ }
980
+ return context;
944
981
  };
945
982
  };
946
983
 
@@ -23,6 +23,10 @@ function SocketIoEngine(script) {
23
23
  this.httpDelegate = new EngineHttp(script);
24
24
  }
25
25
 
26
+ SocketIoEngine.prototype.init = async function () {
27
+ await this.httpDelegate.init();
28
+ };
29
+
26
30
  SocketIoEngine.prototype.createScenario = function (scenarioSpec, ee) {
27
31
  // Adds scenario overridden configuration into the static config
28
32
  this.socketioOpts = { ...this.socketioOpts, ...scenarioSpec.socketio };
package/lib/runner.js CHANGED
@@ -163,6 +163,16 @@ async function runner(script, payload, options, callback) {
163
163
  warnings
164
164
  );
165
165
 
166
+ for (const e of runnerEngines) {
167
+ if (
168
+ e &&
169
+ typeof e.init === 'function' &&
170
+ e.init.constructor.name === 'AsyncFunction'
171
+ ) {
172
+ await e.init();
173
+ }
174
+ }
175
+
166
176
  const promise = new Promise((resolve, _reject) => {
167
177
  ee.run = (contextVars) => {
168
178
  const runState = {
@@ -506,12 +516,23 @@ function $randomString(length = 10) {
506
516
  return s;
507
517
  }
508
518
 
509
- function handleScriptHook(hook, script, hookEvents, contextVars = {}) {
519
+ async function handleScriptHook(hook, script, hookEvents, contextVars = {}) {
510
520
  if (!script[hook]) {
511
521
  return {};
512
522
  }
513
523
 
514
524
  const { loadedEngines: engines } = loadEngines(script, hookEvents);
525
+
526
+ for (const e of engines) {
527
+ if (
528
+ e &&
529
+ typeof e.init === 'function' &&
530
+ e.init.constructor.name === 'AsyncFunction'
531
+ ) {
532
+ await e.init();
533
+ }
534
+ }
535
+
515
536
  const ee = new EventEmitter();
516
537
 
517
538
  return new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.24.0",
3
+ "version": "2.25.0-8732536",
4
4
  "main": "./index.js",
5
5
  "license": "MPL-2.0",
6
6
  "dependencies": {
7
- "@artilleryio/int-commons": "2.20.0",
7
+ "@artilleryio/int-commons": "2.21.0-8732536",
8
8
  "@artilleryio/sketches-js": "^2.1.1",
9
9
  "agentkeepalive": "^4.6.0",
10
10
  "arrivals": "^2.1.2",
11
11
  "async": "^2.6.4",
12
12
  "chalk": "^2.4.2",
13
- "cheerio": "^1.1.2",
13
+ "cheerio": "^1.2.0",
14
14
  "cookie-parser": "^1.4.7",
15
15
  "csv-parse": "^4.16.3",
16
16
  "debug": "^4.4.3",
@@ -22,7 +22,7 @@
22
22
  "fast-deep-equal": "^3.1.3",
23
23
  "filtrex": "^0.5.4",
24
24
  "form-data": "^4.0.5",
25
- "got": "^11.8.5",
25
+ "got": "^14.6.6",
26
26
  "hpagent": "^0.1.1",
27
27
  "https-proxy-agent": "^5.0.0",
28
28
  "lodash": "^4.17.21",