nock 9.4.3 → 9.6.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+
3
+ Nock’s changelog can be found directly in the [GitHub release notes](https://github.com/nock/nock/releases). These are automatically created by [semantic-release](https://github.com/semantic-release/semantic-release) based on their [commit message conventions](https://semantic-release.gitbook.io/semantic-release#commit-message-format).
package/CONTRIBUTING.md CHANGED
@@ -12,10 +12,11 @@ Please note that this project is released with a [Contributor Code of Conduct](.
12
12
  - [Generate README TOC](#generate-readme-toc)
13
13
  - [Running tests](#running-tests)
14
14
  * [Airplane mode](#airplane-mode)
15
+ - [Becoming a maintainer](#becoming-a-maintainer)
15
16
 
16
17
  <!-- tocstop -->
17
18
 
18
- ### Commit Message conventions
19
+ ## Commit Message conventions
19
20
 
20
21
  `nock` releases are automated using [semantic-release](https://github.com/semantic-release/semantic-release).
21
22
  To automatically calculate the correct version number as well as changelogs,
@@ -36,7 +37,7 @@ Other helpful conventions are
36
37
 
37
38
  The commit message(s) of a pull request can be fixed using the `squash & merge` button.
38
39
 
39
- ### Generate README TOC
40
+ ## Generate README TOC
40
41
 
41
42
  Make sure to update the README's table of contents whenever you update the README using the following npm script.
42
43
 
@@ -44,17 +45,34 @@ Make sure to update the README's table of contents whenever you update the READM
44
45
  $ npm run toc
45
46
  ```
46
47
 
47
- ### Running tests
48
+ ## Running tests
48
49
 
49
50
  ```
50
51
  $ npm test
51
52
  ```
52
53
 
53
- #### Airplane mode
54
+ ### Airplane mode
54
55
 
55
56
  Some of the tests depend on online connectivity. To skip them, set the `AIRPLANE` environment variable to some value.
56
57
 
57
58
  ```
58
59
  $ export AIRPLANE=true
59
60
  $ npm test
60
- ```
61
+ ```
62
+
63
+ ## Becoming a maintainer
64
+
65
+ So you want to do more than file a bug or submit a PR? Awesome!
66
+
67
+ Nock is actively interested in having more maintainers. That means that we would love to have you (yes, you) get more involved if you want to! We don't have strict tests that you need to pass to become a maintainer. Instead, all we want is to find people who are frequent contributors, understand what Nock does, and are eager to help make this tool better.
68
+
69
+ Here are some things you can do today to actively show the Nock team that you're interested in helping out in the long term:
70
+
71
+ * **Triage issues!** We have more issues than we have bandwidth to deal with. For some of these issues, there are no labels, no comments suggesting how the issue could be resolved, and no follow-up after months or years of silence. It would be great if the issues actively reflected the state of the project. Go through old issues and suggesting labels in comments, ask for more information, and generally help out with the resolution process. This would be a great help!
72
+ * **Review PRs.** We have a lot of open PRs! Some of these are probably ready to merge, and some of them probably need more work. Any extra eyes on PRs are encouraged. Comment on code patterns you think need work, suggest extra tests, and let us know if a PR 'LGTM' ("looks good to me"). The more reviewers we have, the faster we can merge issues, the better this project becomes.
73
+ * **Help out!** If someone files a bug and no one has responded yet, see if you can resolve it! Suggest PRs, or file them yourself. While most contributors are going to only be interested in their own bugs, great maintainers help out with other people's bugs. This is one of the best ways to become an expert at Nock (and Node.js, JavaScript, or pretty much any project) - helping others.
74
+ * **Write docs.** Are our docs missing something important? Are they not clear? Could they be better? Open a PR!
75
+ * **Suggest examples.** Right now, we have a few examples, but we could always have more. Submit small example files and tutorials. At some point, we'll have to work on a better way to display these - for now, it's great to show others how to solve difficult mocking problems easily with Nock.
76
+ * **Refactor.** This is one of the hardest things to do, but one of the most useful. Go through the code, and find examples where it could be written better - with better variable names, more useful abstractions, and more elegant patterns. Taking away ten lines of code that are unnecessary is more valuable than submitting a hundred new lines, sometimes. Open a PR or a comment and defend your position; ask for feedback.
77
+
78
+ Once you've been around for a bit, ask a current Maintainer - one of [the team members](https://github.com/orgs/nock/people) - whether you can be elevated to Maintainer status and given permissions to close issues and merge PRs. We're interested in how well you know what Nock is about, and how involved you are in the community - not where you're from, how good your English is, or whether or not you can pass a whiteboard test blindfolded. If you think that you've been helpful, let us know. We're friendly, promise. :)
package/README.md CHANGED
@@ -183,7 +183,7 @@ var scope = nock('http://www.example.com')
183
183
 
184
184
  ### Specifying request body
185
185
 
186
- You can specify the request body to be matched as the second argument to the `get`, `post`, `put` or `delete` specifications. There are four types of second argument allowed:
186
+ You can specify the request body to be matched as the second argument to the `get`, `post`, `put` or `delete` specifications. There are five types of second argument allowed:
187
187
 
188
188
  **String**: nock will exact match the stringified request body with the provided string
189
189
 
@@ -193,6 +193,14 @@ nock('http://www.example.com')
193
193
  .reply(200, { id: '123ABC' });
194
194
  ```
195
195
 
196
+ **Buffer**: nock will exact match the stringified request body with the provided buffer
197
+
198
+ ```js
199
+ nock('http://www.example.com')
200
+ .post('/login', Buffer.from([0xff, 0x11]))
201
+ .reply(200, { id: '123ABC' });
202
+ ```
203
+
196
204
  **RegExp**: nock will test the stringified request body against the provided RegExp
197
205
 
198
206
  ```js
@@ -832,6 +840,19 @@ example.pendingMocks() // []
832
840
 
833
841
  example.get("/pathB").optionally().reply(200);
834
842
  example.pendingMocks() // []
843
+
844
+ // You can also pass a boolean argument to `optionally()`. This
845
+ // is useful if you want to conditionally make a mocked request
846
+ // optional.
847
+ var getMock = function(optional) {
848
+ return example.get("/pathC").optionally(optional).reply(200);
849
+ }
850
+
851
+ getMock(true);
852
+ example.pendingMocks() // []
853
+ getMock(false);
854
+ example.pendingMocks() // ["GET http://example.com:80/pathC"]
855
+
835
856
  ```
836
857
 
837
858
  ### Allow __unmocked__ requests on a mocked hostname
@@ -43,8 +43,12 @@ function Interceptor(scope, uri, method, requestBody, interceptorOptions) {
43
43
  this.optional = false;
44
44
  }
45
45
 
46
- Interceptor.prototype.optionally = function optionally() {
47
- this.optional = true;
46
+ Interceptor.prototype.optionally = function optionally(value) {
47
+ // The default behaviour of optionally() with no arguments is to make the mock optional.
48
+ value = (typeof value === 'undefined') ? true : value;
49
+
50
+ this.optional = value;
51
+
48
52
  return this;
49
53
  }
50
54
 
@@ -336,6 +340,7 @@ Interceptor.prototype.match = function match(options, body, hostNameOnly) {
336
340
 
337
341
  Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(options) {
338
342
  var isRegex = _.isRegExp(this.path);
343
+ var isRegexBasePath = _.isRegExp(this.scope.basePath);
339
344
 
340
345
  var method = (options.method || 'GET').toUpperCase()
341
346
  , path = options.path
@@ -362,10 +367,14 @@ Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(o
362
367
  var comparisonKey = isRegex ? this.__nock_scopeKey : this._key;
363
368
  var matchKey = method + ' ' + proto + '://' + options.host + path;
364
369
 
365
- if (isRegex) {
370
+ if (isRegex && !isRegexBasePath) {
366
371
  return !!matchKey.match(comparisonKey) && !!path.match(this.path);
367
372
  }
368
373
 
374
+ if(isRegexBasePath) {
375
+ return !!matchKey.match(this.scope.basePath) && !!path.match(this.path);
376
+ }
377
+
369
378
  return comparisonKey === matchKey;
370
379
  };
371
380
 
package/lib/match_body.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var deepEqual = require('deep-equal');
4
4
  var qs = require('qs');
5
5
  var _ = require('lodash')
6
+ var common = require('./common');
6
7
 
7
8
  module.exports =
8
9
  function matchBody(spec, body) {
@@ -15,6 +16,14 @@ function matchBody(spec, body) {
15
16
  body = body.toString();
16
17
  }
17
18
 
19
+ if (Buffer.isBuffer(spec)) {
20
+ if (common.isBinaryBuffer(spec)) {
21
+ spec = spec.toString('hex');
22
+ } else {
23
+ spec = spec.toString('utf8');
24
+ }
25
+ }
26
+
18
27
  var contentType = (
19
28
  options.headers &&
20
29
  (options.headers['Content-Type'] || options.headers['content-type']) ||
@@ -125,7 +125,6 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
125
125
  };
126
126
 
127
127
  req.socket = response.socket = Socket({ proto: options.proto });
128
- req.socket.connecting = true;
129
128
 
130
129
  req.write = function(buffer, encoding, callback) {
131
130
  debug('write', arguments);
package/lib/socket.js CHANGED
@@ -22,6 +22,7 @@ function Socket(options) {
22
22
  this.writable = true;
23
23
  this.readable = true;
24
24
  this.destroyed = false;
25
+ this.connecting = false;
25
26
 
26
27
  this.setNoDelay = noop;
27
28
  this.setKeepAlive = noop;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "9.4.3",
10
+ "version": "9.6.1",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "contributors": [
13
13
  {
@@ -182,12 +182,10 @@
182
182
  "aws-sdk": "^2.202.0",
183
183
  "coveralls": "^3.0.0",
184
184
  "eslint": "^5.0.0",
185
- "glob": "^7.1.1",
186
185
  "hyperquest": "^2.1.3",
187
186
  "isomorphic-fetch": "^2.2.0",
188
- "istanbul": "^0.4.2",
189
187
  "markdown-toc": "^1.2.0",
190
- "needle": "^2.2.0",
188
+ "needle": "^2.2.2",
191
189
  "nyc": "^12.0.1",
192
190
  "request": "^2.83.0",
193
191
  "request-promise": "^4.2.2",