node-tdd 5.2.1 → 5.2.3

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
@@ -20,12 +20,7 @@ const healer = objectScan(['**.*|*'], {
20
20
  const parentActual = context.actual[depth - 1];
21
21
  const childExpected = parentExpected?.[k];
22
22
  const childActual = parentActual?.[k];
23
- if (
24
- parentActual !== undefined
25
- && !(childExpected instanceof Object)
26
- && !(childActual instanceof Object)
27
- && childExpected === childActual
28
- ) {
23
+ if (childExpected === childActual) {
29
24
  delete parentActual[k];
30
25
  parentActual[property] = value;
31
26
  }
@@ -33,10 +28,12 @@ const healer = objectScan(['**.*|*'], {
33
28
  afterFn: ({ context }) => context.actual[0]
34
29
  });
35
30
 
36
- export default (original, expected, actual) => healer(
37
- original,
38
- {
39
- expected: [expected],
40
- actual: [cloneDeep(actual)]
41
- }
42
- );
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;
@@ -237,17 +234,16 @@ export default (opts) => {
237
234
  }
238
235
 
239
236
  if (anyFlagPresent(['magic', 'response'])) {
237
+ const interceptorBody = tryParseJson(interceptor.body);
240
238
  const responseBody = tryParseJson([
241
239
  healSqs
242
240
  ].reduce(
243
241
  (respBody, fn) => fn(requestBodyString, respBody, scope, req),
244
242
  interceptor.body
245
243
  ));
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
- }
244
+ updateAndRestoreModifiers(pendingMocks[idx].record, 'response', interceptorBody, responseBody);
245
+ // eslint-disable-next-line no-param-reassign
246
+ interceptor.body = 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.1",
4
+ "version": "5.2.3",
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",