nock 10.0.2 → 10.0.3

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
@@ -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/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
  }
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.3",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -46,7 +46,7 @@
46
46
  "restify-clients": "^2.2.0",
47
47
  "rimraf": "^2.6.2",
48
48
  "semantic-release": "^15.0.0",
49
- "superagent": "^3.8.2",
49
+ "superagent": "^4.0.0",
50
50
  "tap": "^12.0.0"
51
51
  },
52
52
  "scripts": {