@artilleryio/int-core 2.2.0-a4feb0d → 2.2.0-c1dac36

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.
@@ -52,7 +52,9 @@ function markEndTime(ee, _, startedAt) {
52
52
  }
53
53
 
54
54
  function isResponseRequired(spec) {
55
- return spec.emit && spec.response && spec.response.channel;
55
+ return (
56
+ spec.emit && spec.response && (spec.response.channel || spec.response.on)
57
+ );
56
58
  }
57
59
 
58
60
  function isAcknowledgeRequired(spec) {
@@ -60,8 +62,20 @@ function isAcknowledgeRequired(spec) {
60
62
  }
61
63
 
62
64
  function processResponse(ee, data, response, context, callback) {
65
+ function isValid(data, response) {
66
+ if (!Array.isArray(response.data)) {
67
+ //`json` key is added at some point to the response.data object, to use with `captureOrMatch` function
68
+ //we should omit it when comparing the response to the data
69
+ const responseDataWithoutJson = _.isObject(response.data)
70
+ ? _.omit(response.data, 'json')
71
+ : response.data;
72
+ return deepEqual(data[0], responseDataWithoutJson);
73
+ }
74
+
75
+ return deepEqual(data, response.data);
76
+ }
63
77
  // Do we have supplied data to validate?
64
- if (response.data && !deepEqual(data, response.data)) {
78
+ if (response.data && !isValid(data, response)) {
65
79
  debug('data is not valid:');
66
80
  debug(data);
67
81
  debug(response);
@@ -186,9 +200,12 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
186
200
  }
187
201
 
188
202
  if (isAcknowledgeRequired(requestSpec)) {
189
- const ackCallback = function () {
203
+ const ackCallback = function (...args) {
190
204
  const response = {
191
- data: template(requestSpec.acknowledge.data, context),
205
+ data: template(
206
+ requestSpec.acknowledge.data || requestSpec.acknowledge.args,
207
+ context
208
+ ),
192
209
  capture: template(requestSpec.acknowledge.capture, context),
193
210
  match: template(requestSpec.acknowledge.match, context)
194
211
  };
@@ -198,8 +215,9 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
198
215
  r.json = '$.0'; // Default to the first callback argument
199
216
  }
200
217
  });
218
+
201
219
  // Acknowledge data can take up multiple arguments of the emit callback
202
- processResponse(ee, arguments, response, context, function (err) {
220
+ processResponse(ee, args, response, context, function (err) {
203
221
  if (!err) {
204
222
  markEndTime(ee, context, startedAt);
205
223
  }
@@ -225,8 +243,14 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
225
243
 
226
244
  if (isResponseRequired(requestSpec)) {
227
245
  const response = {
228
- channel: template(requestSpec.response.channel, context),
229
- data: template(requestSpec.response.data, context),
246
+ channel: template(
247
+ requestSpec.response.channel || requestSpec.response.on,
248
+ context
249
+ ),
250
+ data: template(
251
+ requestSpec.response.data || requestSpec.response.args,
252
+ context
253
+ ),
230
254
  capture: template(requestSpec.response.capture, context),
231
255
  match: template(requestSpec.response.match, context)
232
256
  };
@@ -234,9 +258,9 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
234
258
  // Listen for the socket.io response on the specified channel
235
259
  let done = false;
236
260
 
237
- socketio.on(response.channel, function receive(data) {
261
+ socketio.on(response.channel, function receive(...args) {
238
262
  done = true;
239
- processResponse(ee, data, response, context, function (err) {
263
+ processResponse(ee, args, response, context, function (err) {
240
264
  if (!err) {
241
265
  markEndTime(ee, context, startedAt);
242
266
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.2.0-a4feb0d",
3
+ "version": "2.2.0-c1dac36",
4
4
  "main": "./index.js",
5
5
  "license": "MPL-2.0",
6
6
  "dependencies": {
7
- "@artilleryio/int-commons": "2.0.2-a4feb0d",
7
+ "@artilleryio/int-commons": "2.0.2-c1dac36",
8
8
  "@artilleryio/sketches-js": "^2.1.1",
9
9
  "agentkeepalive": "^4.1.0",
10
10
  "arrivals": "^2.1.2",