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.
- package/CHANGELOG.md +45 -33
- package/README.md +1 -1
- package/coverage/coverage.json +1 -1
- package/coverage/lcov-report/base.css +143 -113
- package/coverage/lcov-report/index.html +55 -35
- package/coverage/lcov-report/nock/index.html +46 -26
- package/coverage/lcov-report/nock/index.js.html +45 -25
- package/coverage/lcov-report/nock/lib/back.js.html +144 -121
- package/coverage/lcov-report/nock/lib/common.js.html +185 -165
- package/coverage/lcov-report/nock/lib/delayed_body.js.html +61 -41
- package/coverage/lcov-report/nock/lib/global_emitter.js.html +42 -22
- package/coverage/lcov-report/nock/lib/index.html +111 -91
- package/coverage/lcov-report/nock/lib/intercept.js.html +219 -244
- package/coverage/lcov-report/nock/lib/interceptor.js.html +309 -259
- package/coverage/lcov-report/nock/lib/match_body.js.html +76 -56
- package/coverage/lcov-report/nock/lib/mixin.js.html +50 -30
- package/coverage/lcov-report/nock/lib/request_overrider.js.html +285 -265
- package/coverage/lcov-report/nock/lib/scope.js.html +204 -184
- package/coverage/lcov-report/nock/lib/socket.js.html +89 -54
- package/coverage/lcov-report/sorter.js +4 -2
- package/coverage/lcov.info +1225 -1213
- package/lib/common.js +2 -2
- package/lib/intercept.js +8 -23
- package/lib/request_overrider.js +1 -1
- package/lib/socket.js +6 -1
- package/package.json +14 -13
- package/tests/browserify-public/browserify-bundle.js +26754 -23296
- package/tests/test_back.js +14 -26
- package/tests/test_back_2.js +10 -5
- package/tests/test_events.js +19 -6
- package/tests/test_intercept.js +168 -146
package/tests/test_intercept.js
CHANGED
|
@@ -15,15 +15,15 @@ var restify = require('restify');
|
|
|
15
15
|
var domain = require('domain');
|
|
16
16
|
var hyperquest = require('hyperquest');
|
|
17
17
|
var _ = require('lodash');
|
|
18
|
+
var async = require('async');
|
|
18
19
|
|
|
19
20
|
var globalCount;
|
|
20
21
|
|
|
21
22
|
nock.enableNetConnect();
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
24
|
+
globalCount = Object.keys(global).length;
|
|
25
|
+
var acceptableLeaks = [
|
|
26
|
+
'_key', '__core-js_shared__', 'fetch', 'Response', 'Headers', 'Request'];
|
|
27
27
|
|
|
28
28
|
test("double activation throws exception", function(t) {
|
|
29
29
|
nock.restore();
|
|
@@ -288,7 +288,6 @@ test("post", function(t) {
|
|
|
288
288
|
});
|
|
289
289
|
|
|
290
290
|
|
|
291
|
-
|
|
292
291
|
test("post with empty response body", function(t) {
|
|
293
292
|
var scope = nock('http://www.google.com')
|
|
294
293
|
.post('/form')
|
|
@@ -439,7 +438,7 @@ test("get with reply callback returning array with headers", function(t) {
|
|
|
439
438
|
}, function(res) {
|
|
440
439
|
res.setEncoding('utf8');
|
|
441
440
|
t.equal(res.statusCode, 202);
|
|
442
|
-
console.log('res.
|
|
441
|
+
console.log('res.headers:', res.headers);
|
|
443
442
|
t.deepEqual(res.headers, {
|
|
444
443
|
'x-key': 'value',
|
|
445
444
|
'x-key-2': 'value 2',
|
|
@@ -1107,6 +1106,8 @@ test("body data is differentiating", function(t) {
|
|
|
1107
1106
|
req.end('def');
|
|
1108
1107
|
});
|
|
1109
1108
|
|
|
1109
|
+
t.end();
|
|
1110
|
+
|
|
1110
1111
|
});
|
|
1111
1112
|
|
|
1112
1113
|
test("chaining", function(t) {
|
|
@@ -1117,41 +1118,30 @@ test("chaining", function(t) {
|
|
|
1117
1118
|
.post('/form')
|
|
1118
1119
|
.reply(201, "OK!");
|
|
1119
1120
|
|
|
1120
|
-
|
|
1121
|
-
repliedCount += 1;
|
|
1122
|
-
if (t === 2) {
|
|
1123
|
-
scope.done();
|
|
1124
|
-
}
|
|
1125
|
-
t.end();
|
|
1126
|
-
}
|
|
1121
|
+
t.tearDown(scope.done.bind(scope));
|
|
1127
1122
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
}, function(res) {
|
|
1123
|
+
t.test("post", function(t) {
|
|
1124
|
+
var req = http.request({
|
|
1125
|
+
host: "www.spiffy.com"
|
|
1126
|
+
, method: 'POST'
|
|
1127
|
+
, path: '/form'
|
|
1128
|
+
, port: 80
|
|
1129
|
+
}, function(res) {
|
|
1136
1130
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
});
|
|
1142
|
-
res.on('data', function(data) {
|
|
1143
|
-
dataCalled = true;
|
|
1144
|
-
t.ok(data instanceof Buffer, "data should be buffer");
|
|
1145
|
-
t.equal(data.toString(), "OK!", "response should match");
|
|
1146
|
-
});
|
|
1131
|
+
t.equal(res.statusCode, 201);
|
|
1132
|
+
res.once('data', function(data) {
|
|
1133
|
+
t.ok(data instanceof Buffer, "data should be buffer");
|
|
1134
|
+
t.equal(data.toString(), "OK!", "response should match");
|
|
1147
1135
|
|
|
1136
|
+
res.once('end', t.end.bind(t));
|
|
1148
1137
|
});
|
|
1149
1138
|
|
|
1150
|
-
req.end();
|
|
1151
1139
|
});
|
|
1152
1140
|
|
|
1141
|
+
req.end();
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1153
1144
|
t.test("get", function(t) {
|
|
1154
|
-
var dataCalled;
|
|
1155
1145
|
var req = http.request({
|
|
1156
1146
|
host: "www.spiffy.com"
|
|
1157
1147
|
, method: 'GET'
|
|
@@ -1160,21 +1150,19 @@ test("chaining", function(t) {
|
|
|
1160
1150
|
}, function(res) {
|
|
1161
1151
|
|
|
1162
1152
|
t.equal(res.statusCode, 200);
|
|
1163
|
-
res.
|
|
1164
|
-
t.ok(dataCalled);
|
|
1165
|
-
scope.done();
|
|
1166
|
-
t.end();
|
|
1167
|
-
});
|
|
1168
|
-
res.on('data', function(data) {
|
|
1169
|
-
dataCalled = true;
|
|
1153
|
+
res.once('data', function(data) {
|
|
1170
1154
|
t.ok(data instanceof Buffer, "data should be buffer");
|
|
1171
1155
|
t.equal(data.toString(), "Hello World!", "response should match");
|
|
1156
|
+
|
|
1157
|
+
res.once('end', t.end.bind(t));
|
|
1172
1158
|
});
|
|
1173
1159
|
|
|
1174
1160
|
});
|
|
1175
1161
|
|
|
1176
1162
|
req.end();
|
|
1177
1163
|
});
|
|
1164
|
+
|
|
1165
|
+
t.end();
|
|
1178
1166
|
});
|
|
1179
1167
|
|
|
1180
1168
|
test("encoding", function(t) {
|
|
@@ -1526,7 +1514,6 @@ test("abort request", function(t) {
|
|
|
1526
1514
|
res.on('close', function(err) {
|
|
1527
1515
|
t.equal(err.code, 'aborted');
|
|
1528
1516
|
scope.done();
|
|
1529
|
-
t.end();
|
|
1530
1517
|
});
|
|
1531
1518
|
|
|
1532
1519
|
res.on('end', function() {
|
|
@@ -1535,6 +1522,7 @@ test("abort request", function(t) {
|
|
|
1535
1522
|
|
|
1536
1523
|
req.once('error', function(err) {
|
|
1537
1524
|
t.equal(err.code, 'ECONNRESET');
|
|
1525
|
+
t.end();
|
|
1538
1526
|
});
|
|
1539
1527
|
|
|
1540
1528
|
req.abort();
|
|
@@ -2457,8 +2445,6 @@ test('persists interceptors', function(t) {
|
|
|
2457
2445
|
});
|
|
2458
2446
|
|
|
2459
2447
|
test("persist reply with file", function(t) {
|
|
2460
|
-
var dataCalled = false
|
|
2461
|
-
|
|
2462
2448
|
var scope = nock('http://www.filereplier.com')
|
|
2463
2449
|
.persist()
|
|
2464
2450
|
.get('/')
|
|
@@ -2466,7 +2452,8 @@ test("persist reply with file", function(t) {
|
|
|
2466
2452
|
.get('/test')
|
|
2467
2453
|
.reply(200, 'Yay!');
|
|
2468
2454
|
|
|
2469
|
-
|
|
2455
|
+
async.each([1,2], function(_, cb) {
|
|
2456
|
+
var dataCalled = false;
|
|
2470
2457
|
var req = http.request({
|
|
2471
2458
|
host: "www.filereplier.com"
|
|
2472
2459
|
, path: '/'
|
|
@@ -2474,8 +2461,9 @@ test("persist reply with file", function(t) {
|
|
|
2474
2461
|
}, function(res) {
|
|
2475
2462
|
|
|
2476
2463
|
t.equal(res.statusCode, 200);
|
|
2477
|
-
res.
|
|
2464
|
+
res.once('end', function() {
|
|
2478
2465
|
t.ok(dataCalled);
|
|
2466
|
+
cb();
|
|
2479
2467
|
});
|
|
2480
2468
|
res.on('data', function(data) {
|
|
2481
2469
|
dataCalled = true;
|
|
@@ -2484,11 +2472,10 @@ test("persist reply with file", function(t) {
|
|
|
2484
2472
|
|
|
2485
2473
|
});
|
|
2486
2474
|
req.end();
|
|
2487
|
-
}
|
|
2488
|
-
t.end();
|
|
2489
|
-
|
|
2475
|
+
}, t.end.bind(t));
|
|
2490
2476
|
});
|
|
2491
2477
|
|
|
2478
|
+
|
|
2492
2479
|
test('(re-)activate after restore', function(t) {
|
|
2493
2480
|
var scope = nock('http://google.com')
|
|
2494
2481
|
.get('/')
|
|
@@ -2728,9 +2715,9 @@ test('enable real HTTP request only for google.com, via string', function(t) {
|
|
|
2728
2715
|
throw "should not deliver this request"
|
|
2729
2716
|
}).on('error', function (err) {
|
|
2730
2717
|
t.equal(err.message, 'Nock: Not allow net connect for "www.amazon.com:80/"');
|
|
2718
|
+
t.end();
|
|
2731
2719
|
});
|
|
2732
2720
|
|
|
2733
|
-
t.end();
|
|
2734
2721
|
nock.enableNetConnect();
|
|
2735
2722
|
});
|
|
2736
2723
|
|
|
@@ -2761,10 +2748,10 @@ test('repeating once', function(t) {
|
|
|
2761
2748
|
|
|
2762
2749
|
http.get('http://zombo.com', function(res) {
|
|
2763
2750
|
t.equal(200, res.statusCode, 'first request');
|
|
2751
|
+
t.end();
|
|
2764
2752
|
});
|
|
2765
2753
|
|
|
2766
2754
|
nock.cleanAll()
|
|
2767
|
-
t.end();
|
|
2768
2755
|
|
|
2769
2756
|
nock.enableNetConnect();
|
|
2770
2757
|
});
|
|
@@ -2777,16 +2764,12 @@ test('repeating twice', function(t) {
|
|
|
2777
2764
|
.twice()
|
|
2778
2765
|
.reply(200, "Hello World!");
|
|
2779
2766
|
|
|
2780
|
-
|
|
2767
|
+
async.each([1,2], function(_, cb) {
|
|
2781
2768
|
http.get('http://zombo.com', function(res) {
|
|
2782
|
-
t.equal(200, res.statusCode
|
|
2769
|
+
t.equal(200, res.statusCode);
|
|
2770
|
+
cb();
|
|
2783
2771
|
});
|
|
2784
|
-
};
|
|
2785
|
-
|
|
2786
|
-
nock.cleanAll()
|
|
2787
|
-
t.end();
|
|
2788
|
-
|
|
2789
|
-
nock.enableNetConnect();
|
|
2772
|
+
}, t.end.bind(t));
|
|
2790
2773
|
});
|
|
2791
2774
|
|
|
2792
2775
|
test('repeating thrice', function(t) {
|
|
@@ -2797,16 +2780,12 @@ test('repeating thrice', function(t) {
|
|
|
2797
2780
|
.thrice()
|
|
2798
2781
|
.reply(200, "Hello World!");
|
|
2799
2782
|
|
|
2800
|
-
|
|
2783
|
+
async.each([1,2,3], function(_, cb) {
|
|
2801
2784
|
http.get('http://zombo.com', function(res) {
|
|
2802
|
-
t.equal(200, res.statusCode
|
|
2785
|
+
t.equal(200, res.statusCode);
|
|
2786
|
+
cb();
|
|
2803
2787
|
});
|
|
2804
|
-
};
|
|
2805
|
-
|
|
2806
|
-
nock.cleanAll()
|
|
2807
|
-
t.end();
|
|
2808
|
-
|
|
2809
|
-
nock.enableNetConnect();
|
|
2788
|
+
}, t.end.bind(t));
|
|
2810
2789
|
});
|
|
2811
2790
|
|
|
2812
2791
|
test('repeating response 4 times', function(t) {
|
|
@@ -2817,19 +2796,14 @@ test('repeating response 4 times', function(t) {
|
|
|
2817
2796
|
.times(4)
|
|
2818
2797
|
.reply(200, "Hello World!");
|
|
2819
2798
|
|
|
2820
|
-
|
|
2799
|
+
async.each([1,2,3,4], function(_, cb) {
|
|
2821
2800
|
http.get('http://zombo.com', function(res) {
|
|
2822
2801
|
t.equal(200, res.statusCode, 'first request');
|
|
2802
|
+
cb();
|
|
2823
2803
|
});
|
|
2824
|
-
};
|
|
2825
|
-
|
|
2826
|
-
nock.cleanAll()
|
|
2827
|
-
t.end();
|
|
2828
|
-
|
|
2829
|
-
nock.enableNetConnect();
|
|
2804
|
+
}, t.end.bind(t));
|
|
2830
2805
|
});
|
|
2831
2806
|
|
|
2832
|
-
|
|
2833
2807
|
test('superagent works', function(t) {
|
|
2834
2808
|
var responseText = 'Yay superagent!';
|
|
2835
2809
|
var headers = { 'Content-Type': 'text/plain'};
|
|
@@ -2927,7 +2901,10 @@ test('response is an http.IncomingMessage instance', function(t) {
|
|
|
2927
2901
|
function checkDuration(t, ms) {
|
|
2928
2902
|
var _end = t.end;
|
|
2929
2903
|
var start = process.hrtime();
|
|
2904
|
+
var ended = false;
|
|
2930
2905
|
t.end = function () {
|
|
2906
|
+
if (ended) return;
|
|
2907
|
+
ended = true;
|
|
2931
2908
|
var fin = process.hrtime(start);
|
|
2932
2909
|
var finMs =
|
|
2933
2910
|
(fin[0] * 1e+9) + // seconds -> ms
|
|
@@ -2942,72 +2919,65 @@ function checkDuration(t, ms) {
|
|
|
2942
2919
|
}
|
|
2943
2920
|
|
|
2944
2921
|
test('calling delay could cause mikealRequest timeout error', function(t) {
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2922
|
+
var scope = nock('http://funk')
|
|
2923
|
+
.get('/')
|
|
2924
|
+
.delay({
|
|
2925
|
+
head: 300
|
|
2926
|
+
})
|
|
2927
|
+
.reply(200, 'OK');
|
|
2951
2928
|
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2929
|
+
mikealRequest({
|
|
2930
|
+
uri: 'http://funk',
|
|
2931
|
+
method: 'GET',
|
|
2932
|
+
timeout: 100
|
|
2933
|
+
}, function (err) {
|
|
2934
|
+
scope.done();
|
|
2935
|
+
t.equal(err && err.code, "ETIMEDOUT");
|
|
2936
|
+
t.end();
|
|
2937
|
+
});
|
|
2961
2938
|
});
|
|
2962
2939
|
|
|
2963
|
-
test('Body delay does not have impact on
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2940
|
+
test('Body delay does not have impact on timeout', function(t) {
|
|
2941
|
+
var scope = nock('http://funk')
|
|
2942
|
+
.get('/')
|
|
2943
|
+
.delay({
|
|
2944
|
+
head: 300,
|
|
2945
|
+
body: 300
|
|
2946
|
+
})
|
|
2947
|
+
.reply(200, 'OK');
|
|
2971
2948
|
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2949
|
+
mikealRequest({
|
|
2950
|
+
uri: 'http://funk',
|
|
2951
|
+
method: 'GET',
|
|
2952
|
+
timeout: 500
|
|
2953
|
+
}, function (err, r, body) {
|
|
2954
|
+
t.equal(err, null);
|
|
2955
|
+
t.equal(body, 'OK');
|
|
2956
|
+
t.equal(r.statusCode, 200);
|
|
2957
|
+
scope.done();
|
|
2958
|
+
t.end();
|
|
2959
|
+
});
|
|
2983
2960
|
});
|
|
2984
2961
|
|
|
2985
2962
|
test('calling delay with "body" and "head" delays the response', function (t) {
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
nock('http://funk')
|
|
2989
|
-
.get('/')
|
|
2990
|
-
.delay({
|
|
2991
|
-
head: 300,
|
|
2992
|
-
body: 300
|
|
2993
|
-
})
|
|
2994
|
-
.reply(200, 'OK');
|
|
2995
|
-
|
|
2996
|
-
http.get('http://funk/', function (res) {
|
|
2997
|
-
res.setEncoding('utf8');
|
|
2998
|
-
|
|
2999
|
-
var body = '';
|
|
2963
|
+
checkDuration(t, 600);
|
|
3000
2964
|
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
2965
|
+
nock('http://funk')
|
|
2966
|
+
.get('/')
|
|
2967
|
+
.delay({
|
|
2968
|
+
head: 300,
|
|
2969
|
+
body: 300
|
|
2970
|
+
})
|
|
2971
|
+
.reply(200, 'OK');
|
|
3004
2972
|
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
2973
|
+
http.get('http://funk/', function (res) {
|
|
2974
|
+
res.once('data', function(data) {
|
|
2975
|
+
t.equal(data.toString(), 'OK');
|
|
2976
|
+
res.once('end', t.end.bind(t));
|
|
3009
2977
|
});
|
|
2978
|
+
});
|
|
3010
2979
|
});
|
|
2980
|
+
|
|
3011
2981
|
test('calling delay with "body" delays the response body', function (t) {
|
|
3012
2982
|
checkDuration(t, 100);
|
|
3013
2983
|
|
|
@@ -3469,6 +3439,7 @@ test('define() works with binary buffers', function(t) {
|
|
|
3469
3439
|
});
|
|
3470
3440
|
|
|
3471
3441
|
test('issue #163 - Authorization header isn\'t mocked', function(t) {
|
|
3442
|
+
nock.enableNetConnect();
|
|
3472
3443
|
function makeRequest(cb) {
|
|
3473
3444
|
var r = http.request(
|
|
3474
3445
|
{
|
|
@@ -4038,6 +4009,7 @@ test('response readable pull stream works as expected', function(t) {
|
|
|
4038
4009
|
, port: 80
|
|
4039
4010
|
}, function(res) {
|
|
4040
4011
|
|
|
4012
|
+
var ended = false;
|
|
4041
4013
|
var responseBody = '';
|
|
4042
4014
|
t.equal(res.statusCode, 200);
|
|
4043
4015
|
res.on('readable', function() {
|
|
@@ -4045,7 +4017,8 @@ test('response readable pull stream works as expected', function(t) {
|
|
|
4045
4017
|
while (null !== (chunk = res.read())) {
|
|
4046
4018
|
responseBody += chunk.toString();
|
|
4047
4019
|
}
|
|
4048
|
-
if (chunk === null) {
|
|
4020
|
+
if (chunk === null && ! ended) {
|
|
4021
|
+
ended = true;
|
|
4049
4022
|
t.equal(responseBody, "this is the response body yeah");
|
|
4050
4023
|
t.end();
|
|
4051
4024
|
}
|
|
@@ -4172,6 +4145,23 @@ test('socket setKeepAlive', function(t) {
|
|
|
4172
4145
|
});
|
|
4173
4146
|
});
|
|
4174
4147
|
|
|
4148
|
+
test('abort destroys socket', function(t) {
|
|
4149
|
+
var scope = nock('http://socketdestroyer.com')
|
|
4150
|
+
.get('/')
|
|
4151
|
+
.reply(200, "hey");
|
|
4152
|
+
|
|
4153
|
+
var req = http.get('http://socketdestroyer.com');
|
|
4154
|
+
req.once('error', function() {
|
|
4155
|
+
// ignore
|
|
4156
|
+
});
|
|
4157
|
+
req.once('socket', function(socket) {
|
|
4158
|
+
req.abort();
|
|
4159
|
+
t.ok(socket.destroyed);
|
|
4160
|
+
t.end();
|
|
4161
|
+
});
|
|
4162
|
+
|
|
4163
|
+
});
|
|
4164
|
+
|
|
4175
4165
|
test('hyperquest works', function(t) {
|
|
4176
4166
|
nock('http://hyperquest.com')
|
|
4177
4167
|
.get('/somepath')
|
|
@@ -4202,6 +4192,28 @@ test('match domain using regexp', function (t) {
|
|
|
4202
4192
|
});
|
|
4203
4193
|
});
|
|
4204
4194
|
|
|
4195
|
+
test('match multiple interceptors with regexp domain (issue-508)', function (t) {
|
|
4196
|
+
var scope = nock(/chainregex/)
|
|
4197
|
+
.get('/')
|
|
4198
|
+
.reply(200, 'Match regex')
|
|
4199
|
+
.get('/')
|
|
4200
|
+
.reply(500, 'Match second intercept');
|
|
4201
|
+
|
|
4202
|
+
mikealRequest.get('http://www.chainregex.com', function(err, res, body) {
|
|
4203
|
+
t.type(err, 'null');
|
|
4204
|
+
t.equal(res.statusCode, 200);
|
|
4205
|
+
t.equal(body, 'Match regex');
|
|
4206
|
+
|
|
4207
|
+
mikealRequest.get('http://www.chainregex.com', function(err, res, body) {
|
|
4208
|
+
t.type(err, 'null');
|
|
4209
|
+
t.equal(res.statusCode, 500);
|
|
4210
|
+
t.equal(body, 'Match second intercept');
|
|
4211
|
+
|
|
4212
|
+
t.end();
|
|
4213
|
+
});
|
|
4214
|
+
});
|
|
4215
|
+
});
|
|
4216
|
+
|
|
4205
4217
|
test('match domain using intercept callback', function (t) {
|
|
4206
4218
|
var validUrl = [
|
|
4207
4219
|
'/cats',
|
|
@@ -4369,7 +4381,7 @@ test('remove interceptor removes given interceptor for regex path', function(t)
|
|
|
4369
4381
|
res.setEncoding('utf8');
|
|
4370
4382
|
t.equal(res.statusCode, 202);
|
|
4371
4383
|
|
|
4372
|
-
res.
|
|
4384
|
+
res.once('data', function(data) {
|
|
4373
4385
|
t.equal(data, 'other-content');
|
|
4374
4386
|
});
|
|
4375
4387
|
|
|
@@ -4441,28 +4453,37 @@ test('you must setup an interceptor for each request', function(t) {
|
|
|
4441
4453
|
|
|
4442
4454
|
test('calling socketDelay will emit a timeout', function (t) {
|
|
4443
4455
|
nock('http://www.example.com')
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4456
|
+
.get('/')
|
|
4457
|
+
.socketDelay(10000)
|
|
4458
|
+
.reply(200, 'OK');
|
|
4459
|
+
|
|
4460
|
+
var timedout = false;
|
|
4461
|
+
var ended = false;
|
|
4447
4462
|
|
|
4448
4463
|
var req = http.request('http://www.example.com', function (res) {
|
|
4449
|
-
|
|
4464
|
+
res.setEncoding('utf8');
|
|
4450
4465
|
|
|
4451
|
-
|
|
4466
|
+
var body = '';
|
|
4452
4467
|
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4468
|
+
res.on('data', function(chunk) {
|
|
4469
|
+
body += chunk;
|
|
4470
|
+
});
|
|
4456
4471
|
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4472
|
+
res.once('end', function() {
|
|
4473
|
+
ended = true;
|
|
4474
|
+
if (! timedout) {
|
|
4475
|
+
t.fail('socket did not timeout when idle');
|
|
4476
|
+
t.end();
|
|
4477
|
+
}
|
|
4478
|
+
});
|
|
4461
4479
|
});
|
|
4462
4480
|
|
|
4463
4481
|
req.setTimeout(5000, function () {
|
|
4482
|
+
timedout = true;
|
|
4483
|
+
if (! ended) {
|
|
4464
4484
|
t.ok(true);
|
|
4465
4485
|
t.end();
|
|
4486
|
+
}
|
|
4466
4487
|
});
|
|
4467
4488
|
|
|
4468
4489
|
req.end();
|
|
@@ -4832,9 +4853,10 @@ test("teardown", function(t) {
|
|
|
4832
4853
|
var leaks = Object.keys(global)
|
|
4833
4854
|
.splice(globalCount, Number.MAX_VALUE);
|
|
4834
4855
|
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
}
|
|
4856
|
+
leaks = leaks.filter(function(key) {
|
|
4857
|
+
return acceptableLeaks.indexOf(key) == -1;
|
|
4858
|
+
});
|
|
4859
|
+
|
|
4838
4860
|
t.deepEqual(leaks, [], 'No leaks');
|
|
4839
4861
|
t.end();
|
|
4840
4862
|
});
|