nock 9.6.1 → 10.0.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,26 @@
1
+ ---
2
+ name: 🐛 Bug report
3
+ about: If something isn't working 🤕
4
+
5
+ ---
6
+
7
+ **What is the expected behavior?**
8
+
9
+ **What is the actual behavior?**
10
+
11
+ **Possible solution**
12
+
13
+ **How to reproduce the issue**
14
+
15
+ Runkit: *[Example link](https://runkit.com/gr2m/node-nock-nock-768)*
16
+
17
+ _Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you._
18
+
19
+ **Does the bug have a test case?**
20
+
21
+ **Versions**
22
+
23
+ | Software | Version(s) |
24
+ |----------|------------|
25
+ | Nock | |
26
+ | Node | |
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: 🚀 Feature request
3
+ about: Let us know if you have a feature request 💡
4
+
5
+ ---
6
+
7
+ **Context**
8
+
9
+ What are you trying to do and how would you want to do it differently? Is it something you currently you cannot do? Is this related to an issue/problem?
10
+
11
+ **Alternatives**
12
+
13
+ Can you achieve the same result doing it in an alternative way? Is the alternative considerable?
14
+
15
+ **Has the feature been requested before?**
16
+
17
+ Please provide a link to the issue.
18
+
19
+ **If the feature request is accepted, would you be willing to submit a PR?**
20
+
21
+ Yes / No _(Help can be provided if you need assistance submitting a PR)_
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: ❓ Support
3
+ about: If you need support, check out Nock on StackOverflow
4
+
5
+ ---
6
+
7
+ <!-- 👆 Click "Preview" for a nicer view! -->
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+ We primarily use GitHub as an issue tracker; for usage and support questions we primairly use StackOverflow. Please tag the questions with `nock` so the community can easily find it. [Go to StackOverflow](https://stackoverflow.com/questions/tagged/nock).
23
+
24
+ If you want to submit a feature request you can do that [here](https://github.com/nock/nock/issues/new?template=feature_request.md) or bug reports [here](https://github.com/nock/nock/issues/new?template=bug_report.md).
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: ❤️ Say thank you
3
+ about: Tell us how you use nock & support our efforts in maintaining Nock
4
+
5
+ ---
6
+
7
+ # ❤️ I'm using Nock
8
+
9
+ If you (or your company) are using Nock - please let us know. We'd love to hear from you!
10
+
11
+ Nock is a community driven project, which means it's not maintained by a company. If you would like to help Nock - any of the following is greatly appreciated.
12
+
13
+ - [ ] Give the repository a star ⭐️
14
+ - [ ] Help out with issues
15
+ - [ ] Review pull requests
16
+ - [ ] Blog about Nock
17
+ - [ ] Make tutorials
18
+ - [ ] Give talks
19
+ - [ ] Support us on [https://opencollective.com/nock](https://opencollective.com/nock)
20
+
21
+ Thank you! 💐
@@ -0,0 +1,19 @@
1
+ # Configuration for lock-threads - https://github.com/dessant/lock-threads
2
+
3
+ # Number of days of inactivity before a closed issue or pull request is locked
4
+ daysUntilLock: 14
5
+
6
+ # Issues and pull requests with these labels will not be locked. Set to `[]` to disable
7
+ exemptLabels: []
8
+
9
+ # Label to add before locking, such as `outdated`. Set to `false` to disable
10
+ lockLabel: false
11
+
12
+ # Comment to post before locking. Set to `false` to disable
13
+ lockComment: >
14
+ This thread has been automatically locked since there has not been
15
+ any recent activity after it was closed. Please open a new issue and
16
+ add a reference to this one if it’s related. Thank you!
17
+
18
+ # Assign `resolved` as the reason for locking. Set to `false` to disable
19
+ setLockReason: true
@@ -0,0 +1,25 @@
1
+ # Configuration for probot-stale - https://github.com/probot/stale
2
+
3
+ # Number of days of inactivity before an Issue or Pull Request becomes stale
4
+ daysUntilStale: 90
5
+
6
+ # Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
7
+ # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
8
+ daysUntilClose: 7
9
+
10
+ # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
11
+ exemptLabels:
12
+ - pinned
13
+
14
+ # Label to use when marking as stale
15
+ staleLabel: stale
16
+
17
+ # Comment to post when marking as stale. Set to `false` to disable
18
+ markComment: >
19
+ This issue has been automatically marked as stale because it has not had
20
+ recent activity. It will be closed if no further activity occurs. We try to
21
+ do our best, but nock is maintained by volunteers and there is only so much
22
+ we can do at a time. Thank you for your contributions.
23
+
24
+ # Limit the number of actions per hour, from 1-30. Default is 30
25
+ limitPerRun: 1
package/.travis.yml CHANGED
@@ -23,14 +23,12 @@ jobs:
23
23
  env: linting
24
24
  script: npm run lint
25
25
  - stage: test
26
- node_js: 9
26
+ node_js: 10
27
27
  script: npm run unit
28
28
  - node_js: 8
29
29
  script: npm run unit
30
30
  - node_js: 6
31
31
  script: npm run unit
32
- - node_js: 4
33
- script: npm run unit
34
32
  - stage: release
35
33
  node_js: lts/*
36
34
  env: semantic-release
package/CONTRIBUTING.md CHANGED
@@ -12,6 +12,7 @@ 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
+ - [Release Process](#release-process)
15
16
  - [Becoming a maintainer](#becoming-a-maintainer)
16
17
 
17
18
  <!-- tocstop -->
@@ -60,6 +61,12 @@ $ export AIRPLANE=true
60
61
  $ npm test
61
62
  ```
62
63
 
64
+ ## Release Process
65
+
66
+ All of our releases are automated using [semantic-release](https://github.com/semantic-release/semantic-release). The commit messages pushed to the master branch trigger new releases. Semantic-release requires that commits follow certain convetions, [described above](#commit-message-conventions). semantic-release creates a GitHub release, adds release notes and publishes the new version to npm. This is why we do not store release notes in the [`CHANGELOG`](CHANGELOG.md) file - they're already on GitHub.
67
+
68
+ We use @nockbot as a separate account for releases, because npm tokens cannot be scoped to a single package. This improves our security model in case of a data breach involving npm tokens. @nockbot's credentials were set up by @gr2m; contact him if for any reason you need to change this in the future.
69
+
63
70
  ## Becoming a maintainer
64
71
 
65
72
  So you want to do more than file a bug or submit a PR? Awesome!
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  [![Build Status](https://travis-ci.org/nock/nock.svg?branch=master)](https://travis-ci.org/nock/nock)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/nock/nock/badge.svg?branch=master)](https://coveralls.io/github/nock/nock?branch=master)
5
5
  [![Greenkeeper](https://badges.greenkeeper.io/nock/nock.svg)](https://greenkeeper.io/)
6
+ [![Backers on Open Collective](https://opencollective.com/nock/backers/badge.svg)](#backers)
7
+ [![Sponsors on Open Collective](https://opencollective.com/nock/sponsors/badge.svg)](#sponsors)
6
8
 
7
9
  > HTTP server mocking and expectations library for Node.js
8
10
 
@@ -59,7 +61,10 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
59
61
  - [Restoring](#restoring)
60
62
  - [Activating](#activating)
61
63
  - [Turning Nock Off (experimental!)](#turning-nock-off-experimental)
62
- - [Enable/Disable real HTTP request](#enabledisable-real-http-request)
64
+ - [Enable/Disable real HTTP requests](#enabledisable-real-http-requests)
65
+ * [Disabling requests](#disabling-requests)
66
+ * [Enabling requests](#enabling-requests)
67
+ * [Resetting NetConnect](#resetting-netconnect)
63
68
  - [Recording](#recording)
64
69
  * [`dont_print` option](#dont_print-option)
65
70
  * [`output_objects` option](#output_objects-option)
@@ -78,6 +83,12 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
78
83
  - [Debugging](#debugging)
79
84
  - [PROTIP](#protip)
80
85
  - [Contributing](#contributing)
86
+ - [Commit Message conventions](#commit-message-conventions)
87
+ - [Generate README TOC](#generate-readme-toc)
88
+ - [Running tests](#running-tests)
89
+ * [Airplane mode](#airplane-mode)
90
+ - [Backers](#backers)
91
+ - [Sponsors](#sponsors)
81
92
  - [License](#license)
82
93
 
83
94
  <!-- tocstop -->
@@ -629,7 +640,7 @@ nock('http://my.server.com')
629
640
  .reply(200, '<html></html>')
630
641
  ```
631
642
 
632
- NOTE: the [`'response'`](http://nodejs.org/api/http.html#http_event_response) event will occur immediately, but the [IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage) will not emit it's `'end'` event until after the delay.
643
+ NOTE: the [`'response'`](http://nodejs.org/api/http.html#http_event_response) event will occur immediately, but the [IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage) will not emit its `'end'` event until after the delay.
633
644
 
634
645
  ### Delay the response
635
646
 
@@ -1021,17 +1032,19 @@ This way you can have your tests hit the real servers just by switching on this
1021
1032
  $ NOCK_OFF=true node my_test.js
1022
1033
  ```
1023
1034
 
1024
- ## Enable/Disable real HTTP request
1035
+ ## Enable/Disable real HTTP requests
1025
1036
 
1026
1037
  By default, any requests made to a host that is not mocked will be executed normally. If you want to block these requests, nock allows you to do so.
1027
1038
 
1039
+ ### Disabling requests
1040
+
1028
1041
  For disabling real http requests.
1029
1042
 
1030
1043
  ```js
1031
1044
  nock.disableNetConnect();
1032
1045
  ```
1033
1046
 
1034
- So, if you try to request any host not 'nocked', it will thrown an `NetConnectNotAllowedError`.
1047
+ So, if you try to request any host not 'nocked', it will throw a `NetConnectNotAllowedError`.
1035
1048
 
1036
1049
  ```js
1037
1050
  nock.disableNetConnect();
@@ -1041,40 +1054,45 @@ req.on('error', function(err){
1041
1054
  });
1042
1055
  // The returned `http.ClientRequest` will emit an error event (or throw if you're not listening for it)
1043
1056
  // This code will log a NetConnectNotAllowedError with message:
1044
- // Nock: Not allow net connect for "google.com:80"
1057
+ // Nock: Disallowed net connect for "google.com:80"
1045
1058
  ```
1046
1059
 
1047
- For enabling real HTTP requests (the default behaviour).
1060
+ ### Enabling requests
1061
+
1062
+ For enabling any real HTTP requests (the default behavior):
1048
1063
 
1049
1064
  ```js
1050
1065
  nock.enableNetConnect();
1051
1066
  ```
1052
1067
 
1053
- You could allow real HTTP request for certain host names by providing a string or a regular expression for the hostname:
1068
+ You could allow real HTTP requests for certain host names by providing a string or a regular expression for the hostname:
1054
1069
 
1055
1070
  ```js
1056
- // using a string
1071
+ // Using a string
1057
1072
  nock.enableNetConnect('amazon.com');
1058
1073
 
1059
- // or a RegExp
1060
- nock.enableNetConnect(/(amazon|github).com/);
1074
+ // Or a RegExp
1075
+ nock.enableNetConnect(/(amazon|github)\.com/);
1061
1076
 
1062
1077
  http.get('http://www.amazon.com/');
1063
- http.get('http://github.com/'); // only for second example
1078
+ http.get('http://github.com/');
1064
1079
 
1065
- // This request will be done!
1066
1080
  http.get('http://google.com/');
1067
- // this will throw NetConnectNotAllowedError with message:
1068
- // Nock: Not allow net connect for "google.com:80"
1081
+ // This will throw NetConnectNotAllowedError with message:
1082
+ // Nock: Disallowed net connect for "google.com:80"
1069
1083
  ```
1070
1084
 
1071
- A common use case when testing local endpoints would be to disable all but local host, then adding in additional nocks for external requests:
1085
+ A common use case when testing local endpoints would be to disable all but localhost, then add in additional nocks for external requests:
1072
1086
 
1073
1087
  ```js
1074
1088
  nock.disableNetConnect();
1075
- nock.enableNetConnect('127.0.0.1'); //Allow localhost connections so we can test local routes and mock servers.
1089
+ // Allow localhost connections so we can test local routes and mock servers.
1090
+ nock.enableNetConnect('127.0.0.1');
1076
1091
  ```
1077
- Then when you're done with the test, you probably want to set everything back to normal:
1092
+
1093
+ ### Resetting NetConnect
1094
+
1095
+ When you're done with the test, you probably want to set everything back to normal:
1078
1096
 
1079
1097
  ```js
1080
1098
  nock.cleanAll();
@@ -1184,7 +1202,7 @@ var nocks = nock.define(nockDefs);
1184
1202
 
1185
1203
  ### `enable_reqheaders_recording` option
1186
1204
 
1187
- Recording request headers by default is deemed more trouble than its worth as some of them depend on the timestamp or other values that may change after the tests have been recorder thus leading to complex postprocessing of recorded tests. Thus by default the request headers are not recorded.
1205
+ Recording request headers by default is deemed more trouble than it's worth as some of them depend on the timestamp or other values that may change after the tests have been recorder thus leading to complex postprocessing of recorded tests. Thus by default the request headers are not recorded.
1188
1206
 
1189
1207
  The genuine use cases for recording request headers (e.g. checking authorization) can be handled manually or by using `enable_reqheaders_recording` in `recorder.rec()` options.
1190
1208
 
@@ -1213,7 +1231,7 @@ nock.recorder.rec({
1213
1231
 
1214
1232
  ### `use_separator` option
1215
1233
 
1216
- By default, nock will wrap it's output with the separator string `<<<<<<-- cut here -->>>>>>` before and after anything it prints, whether to the console or a custom log function given with the `logging` option.
1234
+ By default, nock will wrap its output with the separator string `<<<<<<-- cut here -->>>>>>` before and after anything it prints, whether to the console or a custom log function given with the `logging` option.
1217
1235
 
1218
1236
  To disable this, set `use_separator` to false.
1219
1237
 
@@ -1401,6 +1419,72 @@ Thanks for wanting to contribute! Take a look at our [Contributing Guide](CONTRI
1401
1419
  Please note that this project is released with a [Contributor Code of Conduct](./CODE_OF_CONDUCT.md).
1402
1420
  By participating in this project you agree to abide by its terms.
1403
1421
 
1422
+ ## Commit Message conventions
1423
+
1424
+ `nock` releases are automated using [semantic-release](https://github.com/semantic-release/semantic-release).
1425
+ To automatically calculate the correct version number as well as changelogs,
1426
+ three commit message conventions need to be followed
1427
+
1428
+ - Commit bug fixes with `fix: ...` or `fix(scope): ...` prefix in commit subject
1429
+ - Commit new features with `feat: ...` or `feat(scope): ...` prefix in commit subject
1430
+ - Commit breaking changes by adding `BREAKING CHANGE: ` in the commit body
1431
+ (not the subject line)
1432
+
1433
+ Other helpful conventions are
1434
+
1435
+ - Commit test files with `test: ...` or `test(scope): ...` prefix
1436
+ - Commit changes to `package.json`, `.gitignore` and other meta files with
1437
+ `chore(filename-without-ext): ...`
1438
+ - Commit changes to README files or comments with `docs: ...`
1439
+ - Code style changes with `style: standard`
1440
+
1441
+ The commit message(s) of a pull request can be fixed using the `squash & merge` button.
1442
+
1443
+ ## Generate README TOC
1444
+
1445
+ Make sure to update the README's table of contents whenever you update the README using the following npm script.
1446
+
1447
+ ```
1448
+ $ npm run toc
1449
+ ```
1450
+
1451
+ ## Running tests
1452
+
1453
+ ```
1454
+ $ npm test
1455
+ ```
1456
+
1457
+ ### Airplane mode
1458
+
1459
+ Some of the tests depend on online connectivity. To skip them, set the `AIRPLANE` environment variable to some value.
1460
+
1461
+ ```
1462
+ $ export AIRPLANE=true
1463
+ $ npm test
1464
+ ```
1465
+
1466
+ ## Backers
1467
+
1468
+ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/nock#backer)]
1469
+
1470
+ <a href="https://opencollective.com/nock#backers" target="_blank"><img src="https://opencollective.com/nock/backers.svg?width=890"></a>
1471
+
1472
+
1473
+ ## Sponsors
1474
+
1475
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/nock#sponsor)]
1476
+
1477
+ <a href="https://opencollective.com/nock/sponsor/0/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/0/avatar.svg"></a>
1478
+ <a href="https://opencollective.com/nock/sponsor/1/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/1/avatar.svg"></a>
1479
+ <a href="https://opencollective.com/nock/sponsor/2/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/2/avatar.svg"></a>
1480
+ <a href="https://opencollective.com/nock/sponsor/3/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/3/avatar.svg"></a>
1481
+ <a href="https://opencollective.com/nock/sponsor/4/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/4/avatar.svg"></a>
1482
+ <a href="https://opencollective.com/nock/sponsor/5/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/5/avatar.svg"></a>
1483
+ <a href="https://opencollective.com/nock/sponsor/6/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/6/avatar.svg"></a>
1484
+ <a href="https://opencollective.com/nock/sponsor/7/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/7/avatar.svg"></a>
1485
+ <a href="https://opencollective.com/nock/sponsor/8/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/8/avatar.svg"></a>
1486
+ <a href="https://opencollective.com/nock/sponsor/9/website" target="_blank"><img src="https://opencollective.com/nock/sponsor/9/avatar.svg"></a>
1487
+
1404
1488
  ## License
1405
1489
 
1406
1490
  [MIT](LICENSE)
package/lib/common.js CHANGED
@@ -50,7 +50,7 @@ var isBinaryBuffer = function(buffer) {
50
50
 
51
51
  // Test if the buffer can be reconstructed verbatim from its utf8 encoding.
52
52
  var utfEncodedBuffer = buffer.toString('utf8');
53
- var reconstructedBuffer = new Buffer(utfEncodedBuffer, 'utf8');
53
+ var reconstructedBuffer = Buffer.from(utfEncodedBuffer, 'utf8');
54
54
  var compareBuffers = function(lhs, rhs) {
55
55
  if(lhs.length !== rhs.length) {
56
56
  return false;
@@ -80,7 +80,7 @@ var isBinaryBuffer = function(buffer) {
80
80
  var mergeChunks = function(chunks) {
81
81
 
82
82
  if(_.isEmpty(chunks)) {
83
- return new Buffer(0);
83
+ return Buffer.alloc(0);
84
84
  }
85
85
 
86
86
  // We assume that all chunks are Buffer objects if the first is buffer object.
package/lib/intercept.js CHANGED
@@ -33,7 +33,7 @@ function NetConnectNotAllowedError(host, path) {
33
33
 
34
34
  this.name = 'NetConnectNotAllowedError';
35
35
  this.code = 'ENETUNREACH'
36
- this.message = 'Nock: Not allow net connect for "' + host + path + '"';
36
+ this.message = 'Nock: Disallowed net connect for "' + host + path + '"';
37
37
 
38
38
  Error.captureStackTrace(this, this.constructor);
39
39
  }
@@ -405,7 +405,7 @@ Interceptor.prototype.basicAuth = function basicAuth(options) {
405
405
  var username = options['user'];
406
406
  var password = options['pass'] || '';
407
407
  var name = 'authorization';
408
- var value = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
408
+ var value = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
409
409
  this.interceptorMatchHeaders.push({ name: name, value: value });
410
410
  return this;
411
411
  };
package/lib/recorder.js CHANGED
@@ -56,7 +56,7 @@ var getBodyFromChunks = function(chunks, headers) {
56
56
  body: _.map(chunks, function(chunk) {
57
57
  if(!Buffer.isBuffer(chunk)) {
58
58
  if (typeof chunk === 'string') {
59
- chunk = new Buffer(chunk);
59
+ chunk = Buffer.from(chunk);
60
60
  } else {
61
61
  throw new Error('content-encoded responses must all be binary buffers');
62
62
  }
@@ -330,7 +330,7 @@ function record(rec_options) {
330
330
  res.push = function(data) {
331
331
  if (data) {
332
332
  if (encoding) {
333
- data = new Buffer(data, encoding);
333
+ data = Buffer.from(data, encoding);
334
334
  }
335
335
  dataChunks.push(data);
336
336
  }
@@ -358,7 +358,7 @@ function record(rec_options) {
358
358
  if (data) {
359
359
  debug(thisRecordingId, 'new', proto, 'body chunk');
360
360
  if (! Buffer.isBuffer(data)) {
361
- data = new Buffer(data, encoding);
361
+ data = Buffer.from(data, encoding);
362
362
  }
363
363
  bodyChunks.push(data);
364
364
  }
@@ -373,7 +373,7 @@ function record(rec_options) {
373
373
  if (data) {
374
374
  debug(thisRecordingId, 'new', proto, 'body chunk');
375
375
  if (! Buffer.isBuffer(data)) {
376
- data = new Buffer(data, encoding);
376
+ data = Buffer.from(data, encoding);
377
377
  }
378
378
  bodyChunks.push(data);
379
379
  }
@@ -111,7 +111,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
111
111
 
112
112
  /// options.auth
113
113
  if (options.auth && (! options.headers || ! options.headers.authorization)) {
114
- setHeader(req, 'Authorization', 'Basic ' + (new Buffer(options.auth)).toString('base64'));
114
+ setHeader(req, 'Authorization', 'Basic ' + (Buffer.from(options.auth)).toString('base64'));
115
115
  }
116
116
 
117
117
  if (! req.connection) {
@@ -131,7 +131,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
131
131
  if (!req.aborted) {
132
132
  if (buffer) {
133
133
  if (!Buffer.isBuffer(buffer)) {
134
- buffer = new Buffer(buffer, encoding);
134
+ buffer = Buffer.from(buffer, encoding);
135
135
  }
136
136
  requestBodyBuffers.push(buffer);
137
137
  }
@@ -318,13 +318,13 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
318
318
  emitError(new Error('Gzip encoding is currently not supported in this version of Node.'));
319
319
  return;
320
320
  }
321
- requestBody = String(zlib.gunzipSync(new Buffer(requestBody, 'hex')), 'hex')
321
+ requestBody = String(zlib.gunzipSync(Buffer.from(requestBody, 'hex')), 'hex')
322
322
  } else if (requestBody && common.contentEncoding(req.headers, 'deflate')) {
323
323
  if (typeof zlib.deflateSync !== 'function') {
324
324
  emitError(new Error('Deflate encoding is currently not supported in this version of Node.'));
325
325
  return;
326
326
  }
327
- requestBody = String(zlib.inflateSync(new Buffer(requestBody, 'hex')), 'hex')
327
+ requestBody = String(zlib.inflateSync(Buffer.from(requestBody, 'hex')), 'hex')
328
328
  }
329
329
 
330
330
  requestBody = JSON.parse(requestBody);
@@ -356,7 +356,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
356
356
  }
357
357
 
358
358
  responseBuffers = _.map(buffers, function(buffer) {
359
- return new Buffer(buffer, 'hex');
359
+ return Buffer.from(buffer, 'hex');
360
360
  });
361
361
 
362
362
  } else {
@@ -368,7 +368,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
368
368
  if(isBinaryRequestBodyBuffer && typeof(responseBody) === 'string') {
369
369
  // Try to create the buffer from the interceptor's body response as hex.
370
370
  try {
371
- responseBody = new Buffer(responseBody, 'hex');
371
+ responseBody = Buffer.from(responseBody, 'hex');
372
372
  } catch(err) {
373
373
  debug('exception during Buffer construction from hex data:', responseBody, '-', err);
374
374
  }
@@ -376,7 +376,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
376
376
  // Creating buffers does not necessarily throw errors, check for difference in size
377
377
  if (!responseBody || (interceptor.body.length > 0 && responseBody.length === 0)) {
378
378
  // We fallback on constructing buffer from utf8 representation of the body.
379
- responseBody = new Buffer(interceptor.body, 'utf8');
379
+ responseBody = Buffer.from(interceptor.body, 'utf8');
380
380
  }
381
381
  }
382
382
  }
@@ -402,23 +402,27 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
402
402
  if (responseBody) {
403
403
  debug('transform the response body');
404
404
 
405
- if (Array.isArray(responseBody) &&
406
- responseBody.length >= 2 &&
407
- responseBody.length <= 3 &&
408
- typeof responseBody[0] == 'number')
409
- {
405
+ if (Array.isArray(responseBody)) {
410
406
  debug('response body is array: %j', responseBody);
411
- response.statusCode = Number(responseBody[0]);
412
- debug('new headers: %j', responseBody[2]);
413
- if (! response.headers) response.headers = {};
414
- _.assign(response.headers, responseBody[2] || {});
415
- debug('response.headers after: %j', response.headers);
416
- responseBody = responseBody[1];
417
-
418
- response.rawHeaders = response.rawHeaders || [];
419
- Object.keys(response.headers).forEach(function(key) {
420
- response.rawHeaders.push(key, response.headers[key]);
421
- });
407
+
408
+ if (!isNaN(Number(responseBody[0])))
409
+ {
410
+ response.statusCode = Number(responseBody[0]);
411
+ }
412
+
413
+ if (responseBody.length >= 2 && responseBody.length <= 3)
414
+ {
415
+ debug('new headers: %j', responseBody[2]);
416
+ if (!response.headers) response.headers = {};
417
+ _.assign(response.headers, responseBody[2] || {});
418
+ debug('response.headers after: %j', response.headers);
419
+ responseBody = responseBody[1];
420
+
421
+ response.rawHeaders = response.rawHeaders || [];
422
+ Object.keys(response.headers).forEach(function(key) {
423
+ response.rawHeaders.push(key, response.headers[key]);
424
+ });
425
+ }
422
426
  }
423
427
 
424
428
  if (interceptor.delayInMs) {
@@ -442,7 +446,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
442
446
  });
443
447
  } else if (responseBody && !Buffer.isBuffer(responseBody)) {
444
448
  if (typeof responseBody === 'string') {
445
- responseBody = new Buffer(responseBody);
449
+ responseBody = Buffer.from(responseBody);
446
450
  } else {
447
451
  responseBody = JSON.stringify(responseBody);
448
452
  response.headers['content-type'] = 'application/json';
package/lib/socket.js CHANGED
@@ -58,7 +58,7 @@ Socket.prototype.applyDelay = function applyDelay(delayMs) {
58
58
  };
59
59
 
60
60
  Socket.prototype.getPeerCertificate = function getPeerCertificate() {
61
- return new Buffer((Math.random() * 10000 + Date.now()).toString()).toString('base64');
61
+ return Buffer.from((Math.random() * 10000 + Date.now()).toString()).toString('base64');
62
62
  };
63
63
 
64
64
  Socket.prototype.destroy = function destroy() {
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "9.6.1",
10
+ "version": "10.0.0",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "contributors": [
13
13
  {
@@ -201,7 +201,7 @@
201
201
  "test": "npm run -s unit",
202
202
  "coverage": "nyc tap --harmony ./tests/test_*.js",
203
203
  "coveralls": "cat ./coverage/lcov.info | coveralls",
204
- "lint": "eslint '**/*.js'",
204
+ "lint": "eslint \"**/*.js\"",
205
205
  "toc": "markdown-toc -i README.md && markdown-toc -i CONTRIBUTING.md ",
206
206
  "semantic-release": "semantic-release"
207
207
  },