node-tdd 5.1.0 → 5.2.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.
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import objectScan from 'object-scan';
|
|
2
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
3
|
+
|
|
4
|
+
const last = (arr) => arr[arr.length - 1];
|
|
5
|
+
|
|
6
|
+
const healer = objectScan(['**.*|*'], {
|
|
7
|
+
breakFn: ({
|
|
8
|
+
isMatch, depth, property, context
|
|
9
|
+
}) => {
|
|
10
|
+
if (property === undefined) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
context.expected[depth] = last(context.expected)?.[property];
|
|
14
|
+
context.actual[depth] = last(context.actual)?.[property];
|
|
15
|
+
return isMatch;
|
|
16
|
+
},
|
|
17
|
+
filterFn: ({
|
|
18
|
+
context, depth, property, value
|
|
19
|
+
}) => {
|
|
20
|
+
const k = property.split('|')[0];
|
|
21
|
+
const parentExpected = context.expected[depth - 1];
|
|
22
|
+
const parentActual = context.actual[depth - 1];
|
|
23
|
+
const childExpected = parentExpected?.[k];
|
|
24
|
+
const childActual = parentActual?.[k];
|
|
25
|
+
if (
|
|
26
|
+
parentActual !== undefined
|
|
27
|
+
&& !(childExpected instanceof Object)
|
|
28
|
+
&& !(childActual instanceof Object)
|
|
29
|
+
&& childExpected === childActual
|
|
30
|
+
) {
|
|
31
|
+
delete parentActual[k];
|
|
32
|
+
parentActual[property] = value;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
afterFn: ({ context }) => context.actual[0]
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export default (original, expected, actual) => healer(
|
|
39
|
+
original,
|
|
40
|
+
{
|
|
41
|
+
expected: [expected],
|
|
42
|
+
actual: [cloneDeep(actual)]
|
|
43
|
+
}
|
|
44
|
+
);
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
convertHeaders,
|
|
23
23
|
rewriteHeaders
|
|
24
24
|
} from './request-recorder/util.js';
|
|
25
|
+
import healBody from './request-recorder/heal-body.js';
|
|
25
26
|
|
|
26
27
|
const nockBack = nock.back;
|
|
27
28
|
const nockRecorder = nock.recorder;
|
|
@@ -98,7 +99,7 @@ export default (opts) => {
|
|
|
98
99
|
// convert 404 response code to 500
|
|
99
100
|
const destroyOriginal = req.destroy;
|
|
100
101
|
req.destroy = (err) => {
|
|
101
|
-
if (err
|
|
102
|
+
if (err?.status === 404 && err?.statusCode === 404 && err?.code === 'ERR_NOCK_NO_MATCH') {
|
|
102
103
|
// eslint-disable-next-line no-param-reassign
|
|
103
104
|
err.statusCode = 500;
|
|
104
105
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -180,7 +181,7 @@ export default (opts) => {
|
|
|
180
181
|
const idx = pendingMocks.findIndex((m) => m.idx === scopeIdx);
|
|
181
182
|
const requestBody = nullAsString(tryParseJson(body));
|
|
182
183
|
if (!isEqual(scope.body, requestBody)) {
|
|
183
|
-
pendingMocks[idx].record.body = requestBody;
|
|
184
|
+
pendingMocks[idx].record.body = healBody(pendingMocks[idx].record.body, scope.body, requestBody);
|
|
184
185
|
}
|
|
185
186
|
return scope.body;
|
|
186
187
|
}
|