node-tdd 6.0.3 → 6.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,14 @@
|
|
|
1
|
+
export default (interceptor) => {
|
|
2
|
+
const result = [];
|
|
3
|
+
for (let i = 0; i < interceptor.rawHeaders.length; i += 2) {
|
|
4
|
+
const name = interceptor.rawHeaders[i];
|
|
5
|
+
let value = interceptor.rawHeaders[i + 1];
|
|
6
|
+
if (name.toLowerCase() === 'content-length') {
|
|
7
|
+
value = interceptor.body[
|
|
8
|
+
interceptor.body instanceof Buffer ? 'byteLength' : 'length'
|
|
9
|
+
].toString();
|
|
10
|
+
}
|
|
11
|
+
result.push(name, value);
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
@@ -14,14 +14,14 @@ import nockMock from './request-recorder/nock-mock.js';
|
|
|
14
14
|
import healSqs from './request-recorder/heal-sqs.js';
|
|
15
15
|
import applyModifiers from './request-recorder/apply-modifiers.js';
|
|
16
16
|
import requestInjector from './request-recorder/request-injector.js';
|
|
17
|
-
|
|
17
|
+
import updateAndRestoreModifiers from './request-recorder/update-and-restore-modifiers.js';
|
|
18
|
+
import healResponseHeaders from './request-recorder/heal-response-headers.js';
|
|
18
19
|
import {
|
|
19
20
|
buildKey,
|
|
20
21
|
tryParseJson,
|
|
21
22
|
nullAsString,
|
|
22
23
|
rewriteHeaders
|
|
23
24
|
} from './request-recorder/util.js';
|
|
24
|
-
import updateAndRestoreModifiers from './request-recorder/update-and-restore-modifiers.js';
|
|
25
25
|
|
|
26
26
|
const nockBack = nock.back;
|
|
27
27
|
const nockRecorder = nock.recorder;
|
|
@@ -176,10 +176,14 @@ export default (opts) => {
|
|
|
176
176
|
);
|
|
177
177
|
// eslint-disable-next-line no-param-reassign
|
|
178
178
|
scope.filteringRequestBody = (body) => {
|
|
179
|
+
const idx = pendingMocks.findIndex((m) => m.idx === scopeIdx);
|
|
180
|
+
const record = pendingMocks[idx].record;
|
|
181
|
+
if (record?.body === null) {
|
|
182
|
+
return scope.body;
|
|
183
|
+
}
|
|
179
184
|
if (anyFlagPresent(['magic', 'body'])) {
|
|
180
|
-
const idx = pendingMocks.findIndex((m) => m.idx === scopeIdx);
|
|
181
185
|
const requestBody = nullAsString(tryParseJson(body));
|
|
182
|
-
updateAndRestoreModifiers(
|
|
186
|
+
updateAndRestoreModifiers(record, 'body', scope.body, requestBody);
|
|
183
187
|
return scope.body;
|
|
184
188
|
}
|
|
185
189
|
return body;
|
|
@@ -231,6 +235,16 @@ export default (opts) => {
|
|
|
231
235
|
...rewriteHeaders(pendingMocks[idx].record.reqheaders)
|
|
232
236
|
};
|
|
233
237
|
pendingMocks[idx].record.reqheaders = rewriteHeaders(reqheaders, overwriteHeaders);
|
|
238
|
+
|
|
239
|
+
// heal response headers
|
|
240
|
+
const newHeaders = healResponseHeaders(interceptor);
|
|
241
|
+
if (newHeaders.length === 0) {
|
|
242
|
+
delete pendingMocks[idx].record.rawHeaders;
|
|
243
|
+
} else {
|
|
244
|
+
pendingMocks[idx].record.rawHeaders = newHeaders;
|
|
245
|
+
}
|
|
246
|
+
// eslint-disable-next-line no-param-reassign
|
|
247
|
+
interceptor.rawHeaders = newHeaders; // ensure response handled correctly
|
|
234
248
|
}
|
|
235
249
|
|
|
236
250
|
if (anyFlagPresent(['magic', 'response'])) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-tdd",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.0
|
|
4
|
+
"version": "6.2.0",
|
|
5
5
|
"description": "Drop in extension for mocha to abstract commonly used test setups",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/blackflux/node-tdd#readme",
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@aws-sdk/client-sqs": "3.
|
|
45
|
-
"@babel/core": "7.
|
|
46
|
-
"@babel/eslint-parser": "7.
|
|
47
|
-
"@babel/register": "7.
|
|
44
|
+
"@aws-sdk/client-sqs": "3.821.0",
|
|
45
|
+
"@babel/core": "7.27.4",
|
|
46
|
+
"@babel/eslint-parser": "7.27.1",
|
|
47
|
+
"@babel/register": "7.27.1",
|
|
48
48
|
"@blackflux/axios": "3.0.2",
|
|
49
49
|
"@blackflux/eslint-plugin-rules": "4.0.1",
|
|
50
|
-
"@blackflux/robo-config-plugin": "10.0.
|
|
50
|
+
"@blackflux/robo-config-plugin": "10.0.6",
|
|
51
51
|
"aws-sdk-wrap": "14.0.1",
|
|
52
52
|
"c8": "10.1.3",
|
|
53
53
|
"chai": "5.2.0",
|
|
54
|
-
"eslint": "9.
|
|
54
|
+
"eslint": "9.28.0",
|
|
55
55
|
"eslint-config-airbnb-base": "15.0.0",
|
|
56
56
|
"eslint-plugin-import": "2.31.0",
|
|
57
57
|
"eslint-plugin-json": "4.0.1",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"lodash.get": "4.4.2",
|
|
81
81
|
"lru-cache-ext": "5.0.1",
|
|
82
82
|
"minimist": "1.2.8",
|
|
83
|
-
"nock": "14.0.
|
|
83
|
+
"nock": "14.0.5",
|
|
84
84
|
"normalize-url": "2.0.1",
|
|
85
85
|
"object-scan": "20.0.1",
|
|
86
86
|
"smart-fs": "5.0.2",
|