@artilleryio/int-core 2.3.1-fde8a88 → 2.4.0

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.
@@ -220,9 +220,19 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
220
220
  return function (context, callback) {
221
221
  let processFunc = self.config.processor[requestSpec.function];
222
222
  if (processFunc) {
223
- return processFunc(context, ee, function (hookErr) {
224
- return callback(hookErr, context);
225
- });
223
+ if (processFunc.constructor.name === 'Function') {
224
+ return processFunc(context, ee, function (hookErr) {
225
+ return callback(hookErr, context);
226
+ });
227
+ } else {
228
+ return processFunc(context, ee)
229
+ .then(() => {
230
+ callback(null, context);
231
+ })
232
+ .catch((err) => {
233
+ callback(err, context);
234
+ });
235
+ }
226
236
  } else {
227
237
  debug(`Function "${requestSpec.function}" not defined`);
228
238
  debug('processor: %o', self.config.processor);
@@ -309,12 +319,16 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
309
319
  console.log(`WARNING: custom function ${fn} could not be found`); // TODO: a 'warning' event
310
320
  }
311
321
 
312
- processFunc(requestParams, context, ee, function (err) {
313
- if (err) {
314
- return next(err);
315
- }
316
- return next(null);
317
- });
322
+ if (processFunc.constructor.name === 'Function') {
323
+ processFunc(requestParams, context, ee, function (err) {
324
+ if (err) {
325
+ return next(err);
326
+ }
327
+ return next(null);
328
+ });
329
+ } else {
330
+ processFunc(requestParams, context, ee).then(next).catch(next);
331
+ }
318
332
  },
319
333
  function done(err) {
320
334
  if (err) {
@@ -608,12 +622,24 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
608
622
  // Got does not have res.body which Request.js used to have, so we attach it here:
609
623
  res.body = body;
610
624
 
611
- processFunc(requestParams, res, context, ee, function (err) {
612
- if (err) {
613
- return next(err);
614
- }
615
- return next(null);
616
- });
625
+ if (processFunc.constructor.name === 'Function') {
626
+ processFunc(
627
+ requestParams,
628
+ res,
629
+ context,
630
+ ee,
631
+ function (err) {
632
+ if (err) {
633
+ return next(err);
634
+ }
635
+ return next(null);
636
+ }
637
+ );
638
+ } else {
639
+ processFunc(requestParams, res, context, ee)
640
+ .then(next)
641
+ .catch(next);
642
+ }
617
643
  },
618
644
  function (err) {
619
645
  if (err) {
package/lib/engine_ws.js CHANGED
@@ -141,9 +141,19 @@ WSEngine.prototype.step = function (requestSpec, ee) {
141
141
  return function (context, callback) {
142
142
  const processFunc = self.config.processor[requestSpec.function];
143
143
  if (processFunc) {
144
- processFunc(context, ee, function () {
145
- return callback(null, context);
146
- });
144
+ if (processFunc.constructor.name === 'Function') {
145
+ processFunc(context, ee, function () {
146
+ return callback(null, context);
147
+ });
148
+ } else {
149
+ return processFunc(context, ee)
150
+ .then(() => {
151
+ callback(null, context);
152
+ })
153
+ .catch((err) => {
154
+ callback(err, context);
155
+ });
156
+ }
147
157
  }
148
158
  };
149
159
  }
package/lib/runner.js CHANGED
@@ -77,15 +77,25 @@ function loadEngines(
77
77
  return { loadedEngines, warnings };
78
78
  }
79
79
 
80
- function loadProcessor(script, options) {
80
+ async function loadProcessor(script, options) {
81
+ const absoluteScriptPath = path.resolve(process.cwd(), options.scriptPath);
81
82
  if (script.config.processor) {
82
- const absoluteScriptPath = path.resolve(process.cwd(), options.scriptPath);
83
83
  const processorPath = path.resolve(
84
84
  path.dirname(absoluteScriptPath),
85
85
  script.config.processor
86
86
  );
87
- const processor = require(processorPath);
88
- script.config.processor = processor;
87
+
88
+ if (processorPath.endsWith('.mjs')) {
89
+ const exports = await import(processorPath);
90
+ script.config.processor = Object.assign(
91
+ {},
92
+ script.config.processor,
93
+ exports
94
+ );
95
+ } else {
96
+ // CJS (possibly transplied from TS)
97
+ script.config.processor = require(processorPath);
98
+ }
89
99
  }
90
100
 
91
101
  return script;
@@ -439,7 +449,7 @@ function createContext(script, contextVars, additionalProperties = {}) {
439
449
  $environment: script._environment,
440
450
  $processEnvironment: process.env, // TODO: deprecate
441
451
  $env: process.env,
442
- $testId: global.artillery.testRunId,
452
+ $testId: global.artillery.testRunId
443
453
  },
444
454
  contextVars || {}
445
455
  ),
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.3.1-fde8a88",
3
+ "version": "2.4.0",
4
4
  "main": "./index.js",
5
5
  "license": "MPL-2.0",
6
6
  "dependencies": {
7
- "@artilleryio/int-commons": "2.0.4-fde8a88",
7
+ "@artilleryio/int-commons": "2.0.4",
8
8
  "@artilleryio/sketches-js": "^2.1.1",
9
9
  "agentkeepalive": "^4.1.0",
10
10
  "arrivals": "^2.1.2",