node-tdd 3.3.3 → 3.4.2

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.
package/README.md CHANGED
@@ -36,6 +36,16 @@ describe('Testing some stuff', /* { ...options }, */ () => {
36
36
 
37
37
  Please see tests for further usage examples.
38
38
 
39
+ ### Custom Cassette Logic
40
+
41
+ ### delayConnection
42
+
43
+ Delay the connection by a certain number of ms.
44
+
45
+ ### delayBody
46
+
47
+ Delay the response body by a certain number of ms.
48
+
39
49
  ### Function Kwargs
40
50
 
41
51
  #### dir
@@ -12,6 +12,11 @@ export default (opts) => {
12
12
  }), 'Invalid Options Provided');
13
13
  let original = null;
14
14
 
15
+ const byteToHex = [];
16
+ for (let i = 0; i < 256; i += 1) {
17
+ byteToHex[i] = (i + 0x100).toString(16).slice(1);
18
+ }
19
+
15
20
  return {
16
21
  inject: () => {
17
22
  assert(original === null);
@@ -19,7 +24,8 @@ export default (opts) => {
19
24
  original = {
20
25
  crypto: {
21
26
  randomBytes: crypto.randomBytes,
22
- randomFillSync: crypto.randomFillSync
27
+ randomFillSync: crypto.randomFillSync,
28
+ randomUUID: crypto.randomUUID
23
29
  },
24
30
  Math: {
25
31
  random: Math.random
@@ -57,6 +63,49 @@ export default (opts) => {
57
63
  });
58
64
  return buffer;
59
65
  };
66
+ crypto.randomUUID = () => {
67
+ const rnds = crypto.randomBytes(16);
68
+
69
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
70
+ // eslint-disable-next-line no-bitwise
71
+ rnds[6] = (rnds[6] & 0x0f) | 0x40;
72
+ // eslint-disable-next-line no-bitwise
73
+ rnds[8] = (rnds[8] & 0x3f) | 0x80;
74
+
75
+ return `${
76
+ byteToHex[rnds[0]]
77
+ }${
78
+ byteToHex[rnds[1]]
79
+ }${
80
+ byteToHex[rnds[2]]
81
+ }${
82
+ byteToHex[rnds[3]]
83
+ }-${
84
+ byteToHex[rnds[4]]
85
+ }${
86
+ byteToHex[rnds[5]]
87
+ }-${
88
+ byteToHex[rnds[6]]
89
+ }${
90
+ byteToHex[rnds[7]]
91
+ }-${
92
+ byteToHex[rnds[8]]
93
+ }${
94
+ byteToHex[rnds[9]]
95
+ }-${
96
+ byteToHex[rnds[10]]
97
+ }${
98
+ byteToHex[rnds[11]]
99
+ }${
100
+ byteToHex[rnds[12]]
101
+ }${
102
+ byteToHex[rnds[13]]
103
+ }${
104
+ byteToHex[rnds[14]]
105
+ }${
106
+ byteToHex[rnds[15]]
107
+ }`;
108
+ };
60
109
  Math.random = () => crypto.randomBytes(4).readUInt32LE() / 0xffffffff;
61
110
  },
62
111
  release: () => {
@@ -2,7 +2,6 @@ import crypto from 'crypto';
2
2
  import qs from 'querystring';
3
3
  import get from 'lodash.get';
4
4
 
5
- import { v4 as uuid4 } from 'uuid';
6
5
  import xml2js from 'xml2js';
7
6
 
8
7
  const parseRequestBody = (body) => Object.values(Object
@@ -47,7 +46,7 @@ export default (requestBody, responseBody, scope) => {
47
46
  'SendMessageBatchResultEntry',
48
47
  idx,
49
48
  'MessageId'
50
- ], uuid4())
49
+ ], crypto.randomUUID())
51
50
  }</MessageId>`,
52
51
  `<MD5OfMessageBody>${
53
52
  crypto.createHash('md5').update(MessageBody).digest('hex')
@@ -68,7 +67,7 @@ export default (requestBody, responseBody, scope) => {
68
67
  0,
69
68
  'RequestId',
70
69
  0
71
- ], uuid4())
70
+ ], crypto.randomUUID())
72
71
  }</RequestId>`,
73
72
  '</ResponseMetadata>',
74
73
  '</SendMessageBatchResponse>'
@@ -4,6 +4,7 @@ import path from 'path';
4
4
  import fs from 'smart-fs';
5
5
  import Joi from 'joi-strict';
6
6
  import nock from 'nock';
7
+ import get from 'lodash.get';
7
8
  import cloneDeep from 'lodash.clonedeep';
8
9
  import compareUrls from 'compare-urls';
9
10
  import nockCommon from 'nock/lib/common.js';
@@ -120,8 +121,11 @@ export default (opts) => {
120
121
  }));
121
122
  });
122
123
  } else if (anyFlagPresent(['stub'])) {
124
+ const host = options.host || options.hostname;
125
+ const port = get(options, 'port', { http: 80, https: 443 }[protocol]);
126
+ const scope = `${protocol}://${host}:${port}`;
123
127
  expectedCassette.push({
124
- scope: `${protocol}://${options.host || options.hostname}:${options.port}`,
128
+ scope,
125
129
  method: options.method,
126
130
  path: options.path,
127
131
  body: tryParseJson(body),
@@ -183,6 +187,14 @@ export default (opts) => {
183
187
  scope.on('request', (req, interceptor, requestBodyString) => {
184
188
  const idx = pendingMocks.findIndex((e) => e.idx === scopeIdx);
185
189
 
190
+ // https://github.com/nock/nock/blob/79ee0429050af929c525ae21a326d22796344bfc/lib/interceptor.js#L616
191
+ if (Number.isInteger(pendingMocks[idx]?.record?.delayConnection)) {
192
+ interceptor.delayConnection(pendingMocks[idx].record.delayConnection);
193
+ }
194
+ if (Number.isInteger(pendingMocks[idx]?.record?.delayBody)) {
195
+ interceptor.delayBody(pendingMocks[idx].record.delayBody);
196
+ }
197
+
186
198
  if (anyFlagPresent(['magic', 'headers'])) {
187
199
  // add new headers
188
200
  const reqheaders = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-tdd",
3
3
  "type": "module",
4
- "version": "3.3.3",
4
+ "version": "3.4.2",
5
5
  "description": "Drop in extension for mocha to abstract commonly used test setups",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -42,18 +42,18 @@
42
42
  },
43
43
  "homepage": "https://github.com/blackflux/node-tdd#readme",
44
44
  "devDependencies": {
45
- "@babel/core": "7.17.9",
45
+ "@babel/core": "7.17.10",
46
46
  "@babel/eslint-parser": "7.17.0",
47
47
  "@babel/register": "7.17.7",
48
48
  "@blackflux/eslint-plugin-rules": "2.1.0",
49
- "@blackflux/robo-config-plugin": "7.7.6",
50
- "aws-sdk": "2.1112.0",
51
- "aws-sdk-wrap": "12.0.4",
52
- "axios": "0.26.1",
53
- "c8": "7.11.0",
49
+ "@blackflux/robo-config-plugin": "7.7.12",
50
+ "aws-sdk": "2.1131.0",
51
+ "aws-sdk-wrap": "12.1.3",
52
+ "axios": "0.27.2",
53
+ "c8": "7.11.2",
54
54
  "chai": "4.3.6",
55
55
  "coveralls": "3.1.1",
56
- "eslint": "8.13.0",
56
+ "eslint": "8.15.0",
57
57
  "eslint-config-airbnb-base": "15.0.0",
58
58
  "eslint-plugin-import": "2.26.0",
59
59
  "eslint-plugin-json": "3.1.0",
@@ -87,7 +87,6 @@
87
87
  "smart-fs": "3.0.1",
88
88
  "timekeeper": "2.2.0",
89
89
  "tmp": "0.2.1",
90
- "uuid": "8.3.0",
91
90
  "xml2js": "0.4.23"
92
91
  }
93
92
  }