nock 7.6.0 → 8.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +45 -33
  2. package/README.md +1 -1
  3. package/coverage/coverage.json +1 -1
  4. package/coverage/lcov-report/base.css +143 -113
  5. package/coverage/lcov-report/index.html +55 -35
  6. package/coverage/lcov-report/nock/index.html +46 -26
  7. package/coverage/lcov-report/nock/index.js.html +45 -25
  8. package/coverage/lcov-report/nock/lib/back.js.html +144 -121
  9. package/coverage/lcov-report/nock/lib/common.js.html +185 -165
  10. package/coverage/lcov-report/nock/lib/delayed_body.js.html +61 -41
  11. package/coverage/lcov-report/nock/lib/global_emitter.js.html +42 -22
  12. package/coverage/lcov-report/nock/lib/index.html +111 -91
  13. package/coverage/lcov-report/nock/lib/intercept.js.html +219 -244
  14. package/coverage/lcov-report/nock/lib/interceptor.js.html +309 -259
  15. package/coverage/lcov-report/nock/lib/match_body.js.html +76 -56
  16. package/coverage/lcov-report/nock/lib/mixin.js.html +50 -30
  17. package/coverage/lcov-report/nock/lib/request_overrider.js.html +285 -265
  18. package/coverage/lcov-report/nock/lib/scope.js.html +204 -184
  19. package/coverage/lcov-report/nock/lib/socket.js.html +89 -54
  20. package/coverage/lcov-report/sorter.js +4 -2
  21. package/coverage/lcov.info +1225 -1213
  22. package/lib/common.js +2 -2
  23. package/lib/intercept.js +8 -23
  24. package/lib/request_overrider.js +1 -1
  25. package/lib/socket.js +6 -1
  26. package/package.json +14 -13
  27. package/tests/browserify-public/browserify-bundle.js +26754 -23296
  28. package/tests/test_back.js +14 -26
  29. package/tests/test_back_2.js +10 -5
  30. package/tests/test_events.js +19 -6
  31. package/tests/test_intercept.js +168 -146
@@ -25,7 +25,7 @@ function testNock (t) {
25
25
  }, function(res) {
26
26
 
27
27
  t.equal(res.statusCode, 200);
28
- res.on('end', function() {
28
+ res.once('end', function() {
29
29
  t.ok(dataCalled);
30
30
  scope.done();
31
31
  t.end();
@@ -55,6 +55,11 @@ function nockBackWithFixture (t, scopesLoaded) {
55
55
  });
56
56
  }
57
57
 
58
+ function setOriginalModeOnEnd(t, nockBack) {
59
+ t.once('end', function() {
60
+ nockBack.setMode(originalMode);
61
+ });
62
+ }
58
63
 
59
64
 
60
65
 
@@ -87,21 +92,15 @@ tap.test('nockBack wild tests', function (nw) {
87
92
  testNock(t);
88
93
  });
89
94
 
90
-
91
95
  nw.test('nock back doesn\'t do anything', function (t) {
92
96
  nockBackWithFixture(t, false);
93
97
  });
94
98
 
95
- })
96
- .on('end', function () {
97
-
98
- nockBack.setMode(originalMode);
99
+ setOriginalModeOnEnd(nw, nockBack);
99
100
 
101
+ nw.end();
100
102
  });
101
103
 
102
-
103
-
104
-
105
104
  tap.test('nockBack dryrun tests', function (nw) {
106
105
 
107
106
  // Manually disable net connectivity to confirm that dryrun enables it.
@@ -179,7 +178,7 @@ tap.test('nockBack dryrun tests', function (nw) {
179
178
 
180
179
  });
181
180
 
182
- req.on('error', function(err) {
181
+ req.once('error', function(err) {
183
182
  if (err.code !== 'ECONNREFUSED') {
184
183
  throw err;
185
184
  }
@@ -189,16 +188,12 @@ tap.test('nockBack dryrun tests', function (nw) {
189
188
  req.end();
190
189
  });
191
190
  });
192
- })
193
- .on('end', function () {
194
191
 
195
- nockBack.setMode(originalMode);
192
+ setOriginalModeOnEnd(nw, nockBack);
196
193
 
194
+ nw.end();
197
195
  });
198
196
 
199
-
200
-
201
-
202
197
  tap.test('nockBack record tests', function (nw) {
203
198
  nockBack.setMode('record');
204
199
 
@@ -318,16 +313,10 @@ tap.test('nockBack record tests', function (nw) {
318
313
  });
319
314
 
320
315
  nw.end();
321
- })
322
- .on('end', function () {
323
-
324
- nockBack.setMode(originalMode);
325
316
 
317
+ setOriginalModeOnEnd(nw, nockBack);
326
318
  });
327
319
 
328
-
329
-
330
-
331
320
  tap.test('nockBack lockdown tests', function (nw) {
332
321
  nockBack.fixtures = __dirname + '/fixtures';
333
322
  nockBack.setMode('lockdown');
@@ -358,9 +347,8 @@ tap.test('nockBack lockdown tests', function (nw) {
358
347
 
359
348
  req.end();
360
349
  });
361
- })
362
- .on('end', function () {
363
350
 
364
- nockBack.setMode(originalMode);
351
+ setOriginalModeOnEnd(nw, nockBack);
365
352
 
353
+ nw.end();
366
354
  });
@@ -10,6 +10,12 @@ var fs = require('fs');
10
10
  var originalMode;
11
11
  var fixture;
12
12
 
13
+ function rimrafOnEnd(t) {
14
+ t.once('end', function() {
15
+ rimraf.sync(fixture);
16
+ });
17
+ }
18
+
13
19
  test('setup', function(t) {
14
20
  originalMode = nockBack.currentMode;
15
21
 
@@ -41,8 +47,8 @@ test('recording', function(t) {
41
47
  res.resume();
42
48
  });
43
49
  });
44
- }).once('end', function() {
45
- rimraf.sync(fixture);
50
+
51
+ rimrafOnEnd(t);
46
52
  });
47
53
 
48
54
  test('passes custom options to recorder', function(t) {
@@ -60,9 +66,8 @@ test('passes custom options to recorder', function(t) {
60
66
  // See https://nodejs.org/api/stream.html#stream_class_stream_readable
61
67
  res.resume();
62
68
  });
63
- })
64
- }).once('end', function() {
65
- rimraf.sync(fixture);
69
+ });
70
+ rimrafOnEnd(t);
66
71
  });
67
72
 
68
73
  test('teardown', function(t) {
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var nock = require('../.');
4
- var http = require('http');
5
- var test = require('tap').test;
3
+ var nock = require('../.');
4
+ var http = require('http');
5
+ var test = require('tap').test;
6
6
 
7
7
  test('emits request and replied events', function(t) {
8
8
  var scope = nock('http://eventland')
@@ -23,7 +23,7 @@ test('emits request and replied events', function(t) {
23
23
  });
24
24
 
25
25
  test('emits no match when no match and no mock', function(t) {
26
- nock.emitter.on('no match', function(req) {
26
+ nock.emitter.once('no match', function(req) {
27
27
  t.end();
28
28
  });
29
29
 
@@ -38,13 +38,26 @@ test('emits no match when no match and mocked', function(t) {
38
38
  .reply('howdy');
39
39
 
40
40
 
41
- nock.emitter.on('no match', function(req) {
41
+ var assertion = function(req) {
42
42
  t.equal(req.path, '/definitelymaybe');
43
+ nock.emitter.removeAllListeners('no match');
43
44
  t.end();
44
- });
45
+ }
46
+ var result = nock.emitter.on('no match', assertion);
45
47
 
46
48
  http.get('http://itmayormaynotexistidontknowreally/definitelymaybe')
47
49
  .once('error', ignore);
48
50
  });
49
51
 
52
+ test('emits no match when netConnect is disabled', function(t) {
53
+ nock.disableNetConnect();
54
+ nock.emitter.on('no match', function(req) {
55
+ t.equal(req.hostname, 'jsonip.com')
56
+ nock.emitter.removeAllListeners('no match');
57
+ nock.enableNetConnect();
58
+ t.end();
59
+ });
60
+ http.get('http://jsonip.com').once('error', ignore);
61
+ });
62
+
50
63
  function ignore() {}