node-tdd 5.2.2 → 5.2.4

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.
@@ -1,16 +1,16 @@
1
1
  import objectScan from 'object-scan';
2
2
  import cloneDeep from 'lodash.clonedeep';
3
3
 
4
- const healer = objectScan(['**.*|*'], {
4
+ const restorer = objectScan(['**.*|*'], {
5
5
  breakFn: ({
6
6
  isMatch, depth, property, context
7
7
  }) => {
8
- if (property === undefined) {
8
+ if (depth === 0) {
9
9
  return false;
10
10
  }
11
11
  context.expected[depth] = context.expected[depth - 1]?.[property];
12
12
  context.actual[depth] = context.actual[depth - 1]?.[property];
13
- return isMatch;
13
+ return isMatch || (depth === 1 && property !== context.field);
14
14
  },
15
15
  filterFn: ({
16
16
  context, depth, property, value
@@ -28,10 +28,12 @@ const healer = objectScan(['**.*|*'], {
28
28
  afterFn: ({ context }) => context.actual[0]
29
29
  });
30
30
 
31
- export default (original, expected, actual) => healer(
32
- original,
33
- {
34
- expected: [expected],
35
- actual: [cloneDeep(actual)]
36
- }
37
- );
31
+ export default (original, field, expected, actual) => {
32
+ const context = {
33
+ expected: [{ [field]: expected }],
34
+ actual: [{ [field]: cloneDeep(actual) }],
35
+ field
36
+ };
37
+ const restored = restorer(original, context);
38
+ Object.assign(original, restored);
39
+ };
@@ -6,7 +6,6 @@ import Joi from 'joi-strict';
6
6
  import nock from 'nock';
7
7
  import get from 'lodash.get';
8
8
  import cloneDeep from 'lodash.clonedeep';
9
- import isEqual from 'lodash.isequal';
10
9
  import nockCommon from 'nock/lib/common.js';
11
10
  import compareUrls from '../util/compare-urls.js';
12
11
  import nockListener from './request-recorder/nock-listener.js';
@@ -22,7 +21,7 @@ import {
22
21
  convertHeaders,
23
22
  rewriteHeaders
24
23
  } from './request-recorder/util.js';
25
- import healBody from './request-recorder/heal-body.js';
24
+ import updateAndRestoreModifiers from './request-recorder/update-and-restore-modifiers.js';
26
25
 
27
26
  const nockBack = nock.back;
28
27
  const nockRecorder = nock.recorder;
@@ -180,9 +179,7 @@ export default (opts) => {
180
179
  if (anyFlagPresent(['magic', 'body'])) {
181
180
  const idx = pendingMocks.findIndex((m) => m.idx === scopeIdx);
182
181
  const requestBody = nullAsString(tryParseJson(body));
183
- if (!isEqual(scope.body, requestBody)) {
184
- pendingMocks[idx].record.body = healBody(pendingMocks[idx].record.body, scope.body, requestBody);
185
- }
182
+ updateAndRestoreModifiers(pendingMocks[idx].record, 'body', scope.body, requestBody);
186
183
  return scope.body;
187
184
  }
188
185
  return body;
@@ -243,11 +240,10 @@ export default (opts) => {
243
240
  (respBody, fn) => fn(requestBodyString, respBody, scope, req),
244
241
  interceptor.body
245
242
  ));
246
- if (!isEqual(interceptor.body, responseBody)) {
247
- // eslint-disable-next-line no-param-reassign
248
- interceptor.body = responseBody;
249
- pendingMocks[idx].record.response = responseBody;
250
- }
243
+ const interceptorBody = tryParseJson(interceptor.body);
244
+ // eslint-disable-next-line no-param-reassign
245
+ interceptor.body = responseBody;
246
+ updateAndRestoreModifiers(pendingMocks[idx].record, 'response', interceptorBody, responseBody);
251
247
  }
252
248
 
253
249
  expectedCassette.push(pendingMocks[idx].record);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-tdd",
3
3
  "type": "module",
4
- "version": "5.2.2",
4
+ "version": "5.2.4",
5
5
  "description": "Drop in extension for mocha to abstract commonly used test setups",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -78,7 +78,6 @@
78
78
  "joi-strict": "3.0.1",
79
79
  "lodash.clonedeep": "4.5.0",
80
80
  "lodash.get": "4.4.2",
81
- "lodash.isequal": "4.5.0",
82
81
  "lru-cache-ext": "4.0.0",
83
82
  "minimist": "1.2.8",
84
83
  "nock": "13.5.4",