@artilleryio/int-core 2.3.1-fde8a88 → 2.4.0-042221c
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/lib/engine_http.js +48 -22
- package/lib/engine_ws.js +13 -3
- package/lib/runner.js +15 -5
- package/package.json +4 -4
package/lib/engine_http.js
CHANGED
|
@@ -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
|
-
|
|
224
|
-
return
|
|
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);
|
|
@@ -280,7 +290,8 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
280
290
|
const requestParams = _.extend(_.clone(params), {
|
|
281
291
|
url: maybePrependBase(params.url || params.uri, config), // *NOT* templating here
|
|
282
292
|
method: method,
|
|
283
|
-
timeout: timeout * 1000
|
|
293
|
+
timeout: timeout * 1000,
|
|
294
|
+
uuid: crypto.randomUUID()
|
|
284
295
|
});
|
|
285
296
|
|
|
286
297
|
if (context._enableCookieJar) {
|
|
@@ -309,12 +320,16 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
309
320
|
console.log(`WARNING: custom function ${fn} could not be found`); // TODO: a 'warning' event
|
|
310
321
|
}
|
|
311
322
|
|
|
312
|
-
processFunc
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
323
|
+
if (processFunc.constructor.name === 'Function') {
|
|
324
|
+
processFunc(requestParams, context, ee, function (err) {
|
|
325
|
+
if (err) {
|
|
326
|
+
return next(err);
|
|
327
|
+
}
|
|
328
|
+
return next(null);
|
|
329
|
+
});
|
|
330
|
+
} else {
|
|
331
|
+
processFunc(requestParams, context, ee).then(next).catch(next);
|
|
332
|
+
}
|
|
318
333
|
},
|
|
319
334
|
function done(err) {
|
|
320
335
|
if (err) {
|
|
@@ -548,7 +563,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
548
563
|
let haveFailedCaptures = false;
|
|
549
564
|
|
|
550
565
|
if (result !== null) {
|
|
551
|
-
ee.emit('trace:http:capture', result, uuid);
|
|
566
|
+
ee.emit('trace:http:capture', result, requestParams.uuid);
|
|
552
567
|
if (
|
|
553
568
|
Object.keys(result.matches).length > 0 ||
|
|
554
569
|
Object.keys(result.captures).length > 0
|
|
@@ -608,12 +623,24 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
608
623
|
// Got does not have res.body which Request.js used to have, so we attach it here:
|
|
609
624
|
res.body = body;
|
|
610
625
|
|
|
611
|
-
processFunc
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
626
|
+
if (processFunc.constructor.name === 'Function') {
|
|
627
|
+
processFunc(
|
|
628
|
+
requestParams,
|
|
629
|
+
res,
|
|
630
|
+
context,
|
|
631
|
+
ee,
|
|
632
|
+
function (err) {
|
|
633
|
+
if (err) {
|
|
634
|
+
return next(err);
|
|
635
|
+
}
|
|
636
|
+
return next(null);
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
} else {
|
|
640
|
+
processFunc(requestParams, res, context, ee)
|
|
641
|
+
.then(next)
|
|
642
|
+
.catch(next);
|
|
643
|
+
}
|
|
617
644
|
},
|
|
618
645
|
function (err) {
|
|
619
646
|
if (err) {
|
|
@@ -663,11 +690,10 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
663
690
|
|
|
664
691
|
requestParams.retry = 0; // disable retries - ignored when using streams
|
|
665
692
|
|
|
666
|
-
const uuid = crypto.randomUUID();
|
|
667
693
|
let totalDownloaded = 0;
|
|
668
|
-
request(requestParams)
|
|
694
|
+
request(_.omit(requestParams, ['uuid']))
|
|
669
695
|
.on('request', function (req) {
|
|
670
|
-
ee.emit('trace:http:request', requestParams, uuid);
|
|
696
|
+
ee.emit('trace:http:request', requestParams, requestParams.uuid);
|
|
671
697
|
|
|
672
698
|
debugRequests('request start: %s', req.path);
|
|
673
699
|
ee.emit('counter', 'http.requests', 1);
|
|
@@ -676,7 +702,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
676
702
|
res.on('end', () => {
|
|
677
703
|
ee.emit('counter', 'http.downloaded_bytes', totalDownloaded);
|
|
678
704
|
});
|
|
679
|
-
ee.emit('trace:http:response', res, uuid);
|
|
705
|
+
ee.emit('trace:http:response', res, requestParams.uuid);
|
|
680
706
|
self._handleResponse(
|
|
681
707
|
requestParams,
|
|
682
708
|
res,
|
|
@@ -691,7 +717,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
691
717
|
totalDownloaded = progress.total;
|
|
692
718
|
})
|
|
693
719
|
.on('error', function (err, body, res) {
|
|
694
|
-
ee.emit('trace:http:error', err, uuid);
|
|
720
|
+
ee.emit('trace:http:error', err, requestParams.uuid);
|
|
695
721
|
if (err.name === 'HTTPError') {
|
|
696
722
|
return;
|
|
697
723
|
}
|
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
|
|
145
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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
|
+
"version": "2.4.0-042221c",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@artilleryio/int-commons": "2.0.4-
|
|
7
|
+
"@artilleryio/int-commons": "2.0.4-042221c",
|
|
8
8
|
"@artilleryio/sketches-js": "^2.1.1",
|
|
9
9
|
"agentkeepalive": "^4.1.0",
|
|
10
10
|
"arrivals": "^2.1.2",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"lint": "eslint --ext \".js,.ts,.tsx\" .",
|
|
40
40
|
"lint-fix": "npm run lint -- --fix",
|
|
41
41
|
"test": "npm run test:unit && npm run test:acceptance",
|
|
42
|
-
"test:unit": "tap --no-coverage --color --timeout=300 test/
|
|
43
|
-
"test:acceptance": "
|
|
42
|
+
"test:unit": "tap --no-coverage --color --timeout=300 test/unit/*.test.js",
|
|
43
|
+
"test:acceptance": "tap --no-coverage --color --timeout 300 test/acceptance/*.test.js && tap --no-coverage --color --timeout=300 test/acceptance/**/*.test.js"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@hapi/basic": "^6.0.0",
|