nock 10.0.2 → 10.0.6

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/.travis.yml CHANGED
@@ -9,12 +9,15 @@ branches:
9
9
  only:
10
10
  - master
11
11
  - /^greenkeeper.*$/
12
+ - beta # semantic-release preview releases
13
+ - next # semantic-release @next releases
14
+ - /^\d+\.x$/ # semantic-release maintenance releases
12
15
 
13
16
  stages:
14
17
  - lint
15
18
  - test
16
19
  - name: release
17
- if: branch = master AND type IN (push)
20
+ if: branch =~ /^(\d+\.x|master|next|beta)$/ AND type IN (push)
18
21
 
19
22
  jobs:
20
23
  include:
package/CONTRIBUTING.md CHANGED
@@ -9,12 +9,16 @@ Please note that this project is released with a [Contributor Code of Conduct](.
9
9
  <!-- toc -->
10
10
 
11
11
  - [Commit Message conventions](#commit-message-conventions)
12
+ - [Beta / Next / Maintenance releases](#beta--next--maintenance-releases)
13
+ * [Backport a fix / feature to a previous version](#backport-a-fix--feature-to-a-previous-version)
14
+ * [Submit a Beta / Next release](#submit-a-beta--next-release)
12
15
  - [Generate README TOC](#generate-readme-toc)
13
16
  - [Running tests](#running-tests)
14
17
  * [Airplane mode](#airplane-mode)
15
18
  - [Release Process](#release-process)
16
19
  - [GitHub Apps](#github-apps)
17
20
  - [Becoming a maintainer](#becoming-a-maintainer)
21
+ - [Generating the CONTRIBUTORS.md file](#generating-the-contributorsmd-file)
18
22
 
19
23
  <!-- tocstop -->
20
24
 
@@ -39,6 +43,29 @@ Other helpful conventions are
39
43
 
40
44
  The commit message(s) of a pull request can be fixed using the `squash & merge` button.
41
45
 
46
+ ## Beta / Next / Maintenance releases
47
+
48
+ We use [semantic-release](https://github.com/semantic-release/semantic-release) to automate the release of new versions based on semantic commit messages as described above. Depending on the branch that a new pull request is merged into, it is published to different versions using different [npm dist-tags](https://docs.npmjs.com/cli/dist-tag).
49
+
50
+ - `master`: Publish with `@latest`, or if the commits have been merged into `next` branch before, update the `@latest` dist-tag to point at the new version
51
+ - `next`: Publish with `@next`
52
+ - `beta`: Publish to `X.0.0-beta.Y`, where `X` is the next breaking version and `Y` is number that gets increased with each release.
53
+ - `[Version].x`: For example `10.x`, where `10` is the major release number. No breaking changes are allowed on this branch. Publishes fix/feature versions to `[Version]` using a `@release-@[version].x` release tag
54
+
55
+ ### Backport a fix / feature to a previous version
56
+
57
+ If you want to **backport a fix** to version 10, and the last version released on version 10 is `10.0.4`, then you have to follow these steps
58
+
59
+ 1. Create the `[Version].x` branch unless it already exists. If you don’t have write access, ask one of the maintainers to do it for you. In this example, then command is `git checkout -b 10.x v10.0.4`.
60
+ 2. Push the branch to GitHub: `git push -u origin $(git symbolic-ref --short HEAD)`
61
+ 3. Create a new branch based on `10.x`
62
+ 4. Make your changes
63
+ 5. Submit the pull request against the `10.x` branch
64
+
65
+ ### Submit a Beta / Next release
66
+
67
+ Create a new branch based off `beta` or `next`, depending on what you want. Make your changes and submit them to the same branches. If either `beta` or `next` is outdated, ask a maintainer to re-create them from `master`
68
+
42
69
  ## Generate README TOC
43
70
 
44
71
  Make sure to update the README's table of contents whenever you update the README using the following npm script.
package/README.md CHANGED
@@ -1144,7 +1144,7 @@ var nockCalls = nock.recorder.play();
1144
1144
 
1145
1145
  The `nockCalls` var will contain an array of strings representing the generated code you need.
1146
1146
 
1147
- Copy and paste that code into your tests, customize at will, and you're done! You can call `nock.recorder.reset()` to remove already recorded calls from the array that `nock.recorder.play()` returns.
1147
+ Copy and paste that code into your tests, customize at will, and you're done! You can call `nock.recorder.clear()` to remove already recorded calls from the array that `nock.recorder.play()` returns.
1148
1148
 
1149
1149
  (Remember that you should do this one test at a time).
1150
1150
 
@@ -1333,24 +1333,6 @@ nockBack.setMode('record');
1333
1333
 
1334
1334
  nockBack.fixtures = __dirname + '/nockFixtures'; //this only needs to be set once in your test helper
1335
1335
 
1336
- var before = function(scope) {
1337
- scope.filteringRequestBody = function(body, aRecordedBody) {
1338
- if (typeof(body) !== 'string' || typeof(aRecordedBody) !== 'string') {
1339
- return body;
1340
- }
1341
-
1342
- var recordedBodyResult = /timestamp:([0-9]+)/.exec(aRecordedBody);
1343
- if (!recordedBodyResult) {
1344
- return body;
1345
- }
1346
-
1347
- var recordedTimestamp = recordedBodyResult[1];
1348
- return body.replace(/(timestamp):([0-9]+)/g, function(match, key, value) {
1349
- return key + ':' + recordedTimestamp;
1350
- });
1351
- };
1352
- }
1353
-
1354
1336
  // recording of the fixture
1355
1337
  nockBack('zomboFixture.json', function(nockDone) {
1356
1338
  request.get('http://zombo.com', function(err, res, body) {
@@ -1390,10 +1372,38 @@ As an optional second parameter you can pass the following options
1390
1372
  - `afterRecord`: a postprocessing function, gets called after recording. Is passed the array of scopes recorded and should return the array scopes to save to the fixture
1391
1373
  - `recorder`: custom options to pass to the recorder
1392
1374
 
1375
+ ##### Example
1376
+
1377
+ ```javascript
1378
+ var beforeFunc = function(scope) {
1379
+ scope.filteringRequestBody = function(body, aRecordedBody) {
1380
+ if (typeof(body) !== 'string' || typeof(aRecordedBody) !== 'string') {
1381
+ return body;
1382
+ }
1383
+
1384
+ var recordedBodyResult = /timestamp:([0-9]+)/.exec(aRecordedBody);
1385
+ if (!recordedBodyResult) {
1386
+ return body;
1387
+ }
1388
+
1389
+ var recordedTimestamp = recordedBodyResult[1];
1390
+ return body.replace(/(timestamp):([0-9]+)/g, function(match, key, value) {
1391
+ return key + ':' + recordedTimestamp;
1392
+ });
1393
+ };
1394
+ }
1395
+
1396
+ nockBack('zomboFixture.json', { before: beforeFunc }, function(nockDone) {
1397
+ request.get('http://zombo.com', function(err, res, body) {
1398
+ // do your tests
1399
+ nockDone();
1400
+ }
1401
+ }
1402
+ ```
1393
1403
 
1394
1404
  #### Modes
1395
1405
 
1396
- to set the mode call `nockBack.setMode(mode)` or run the tests with the `NOCK_BACK_MODE` environment variable set before loading nock. If the mode needs to be changed programmatically, the following is valid: `nockBack.setMode(nockBack.currentMode)`
1406
+ To set the mode call `nockBack.setMode(mode)` or run the tests with the `NOCK_BACK_MODE` environment variable set before loading nock. If the mode needs to be changed programmatically, the following is valid: `nockBack.setMode(nockBack.currentMode)`
1397
1407
 
1398
1408
  - wild: all requests go out to the internet, don't replay anything, doesn't record anything
1399
1409
 
package/lib/intercept.js CHANGED
@@ -13,9 +13,9 @@ var RequestOverrider = require('./request_overrider'),
13
13
  URL = require('url').URL,
14
14
  _ = require('lodash'),
15
15
  debug = require('debug')('nock.intercept'),
16
- timers = require('timers'),
17
16
  EventEmitter = require('events').EventEmitter,
18
- globalEmitter = require('./global_emitter');
17
+ globalEmitter = require('./global_emitter'),
18
+ timers = require('timers');
19
19
 
20
20
 
21
21
  /**
@@ -21,6 +21,10 @@ module.exports = Interceptor;
21
21
  function Interceptor(scope, uri, method, requestBody, interceptorOptions) {
22
22
  this.scope = scope;
23
23
  this.interceptorMatchHeaders = [];
24
+
25
+ if (typeof method === 'undefined' || !method) {
26
+ throw new Error('The "method" parameter is required for an intercept call.');
27
+ }
24
28
  this.method = method.toUpperCase();
25
29
  this.uri = uri;
26
30
  this._key = this.method + ' ' + scope.basePath + scope.basePathname + (typeof uri === 'string' ? '' : '/') + uri;
package/lib/match_body.js CHANGED
@@ -10,12 +10,19 @@ function matchBody(spec, body) {
10
10
  if (typeof spec === 'undefined') {
11
11
  return true;
12
12
  }
13
+
13
14
  var options = this || {};
14
15
 
15
16
  if (Buffer.isBuffer(body)) {
16
17
  body = body.toString();
17
18
  }
18
19
 
20
+ if (spec instanceof RegExp) {
21
+ if (typeof body === "string") {
22
+ return body.match(spec);
23
+ }
24
+ }
25
+
19
26
  if (Buffer.isBuffer(spec)) {
20
27
  if (common.isBinaryBuffer(spec)) {
21
28
  spec = spec.toString('hex');
@@ -54,14 +61,6 @@ function matchBody(spec, body) {
54
61
  body = body.replace(/\r?\n|\r/g, '');
55
62
  }
56
63
 
57
- if (spec instanceof RegExp) {
58
- if (typeof body === "string") {
59
- return body.match(spec);
60
- } else {
61
- return qs.stringify(body).match(spec);
62
- }
63
- }
64
-
65
64
  if (!isMultipart && typeof spec === "string") {
66
65
  spec = spec.replace(/\r?\n|\r/g, '');
67
66
  }
@@ -10,10 +10,10 @@ var EventEmitter = require('events').EventEmitter,
10
10
  Socket = require('./socket'),
11
11
  _ = require('lodash'),
12
12
  debug = require('debug')('nock.request_overrider'),
13
- timers = require('timers'),
14
13
  ReadableStream = require('stream').Readable,
15
14
  globalEmitter = require('./global_emitter'),
16
- zlib = require('zlib');
15
+ zlib = require('zlib'),
16
+ timers = require('timers');
17
17
 
18
18
  function getHeader(request, name) {
19
19
  if (!request._headers) {
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "10.0.2",
10
+ "version": "10.0.6",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -16,9 +16,9 @@
16
16
  "bugs": {
17
17
  "url": "http://github.com/nock/nock/issues"
18
18
  },
19
- "engines": [
20
- "node >= 4.0"
21
- ],
19
+ "engines": {
20
+ "node": ">= 6.0"
21
+ },
22
22
  "main": "./index",
23
23
  "dependencies": {
24
24
  "chai": "^4.1.2",
@@ -32,12 +32,14 @@
32
32
  "semver": "^5.5.0"
33
33
  },
34
34
  "devDependencies": {
35
+ "acorn": "^6.0.4",
35
36
  "async": "^2.6.0",
36
37
  "aws-sdk": "^2.202.0",
37
38
  "coveralls": "^3.0.0",
38
39
  "eslint": "^5.0.0",
39
40
  "hyperquest": "^2.1.3",
40
41
  "isomorphic-fetch": "^2.2.0",
42
+ "lolex": "^3.0.0",
41
43
  "markdown-toc": "^1.2.0",
42
44
  "needle": "^2.2.2",
43
45
  "nyc": "^12.0.1",
@@ -45,8 +47,8 @@
45
47
  "request-promise": "^4.2.2",
46
48
  "restify-clients": "^2.2.0",
47
49
  "rimraf": "^2.6.2",
48
- "semantic-release": "^15.0.0",
49
- "superagent": "^3.8.2",
50
+ "semantic-release": "^16.0.0-beta.13",
51
+ "superagent": "^4.0.0",
50
52
  "tap": "^12.0.0"
51
53
  },
52
54
  "scripts": {
@@ -65,7 +67,7 @@
65
67
  "text-summary"
66
68
  ],
67
69
  "exclude": [
68
- "tests/test_*.js"
70
+ "tests/"
69
71
  ]
70
72
  },
71
73
  "license": "MIT"
package/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- repo_token: sGdtRYQiEqoTvWMx1nlnyeXJfUHQQyxrw