nock 9.0.9 → 9.0.13

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 (69) hide show
  1. package/.npmignore +2 -0
  2. package/.travis.yml +1 -1
  3. package/CHANGELOG.md +9 -4
  4. package/lib/intercept.js +5 -0
  5. package/lib/match_body.js +1 -1
  6. package/package.json +6 -2
  7. package/.nyc_output/0cfc9aa0c50eae765941a555f8482a68.json +0 -1
  8. package/.nyc_output/0ecdf591be62cb4571ebf9c4df59da37.json +0 -1
  9. package/.nyc_output/1df5c7adcf4885ae588bf8be3e508036.json +0 -1
  10. package/.nyc_output/2db2fc1c81ebebec5066673d7751e720.json +0 -1
  11. package/.nyc_output/2f9ccd224c0ce9793bb47cb95818e613.json +0 -1
  12. package/.nyc_output/302922273ee8b73467d3d8f160d41764.json +0 -1
  13. package/.nyc_output/402abf6bfd9ba80ba17d063c7aff8c5c.json +0 -1
  14. package/.nyc_output/4192a6afdd7ca9d506a9007e60f313c6.json +0 -1
  15. package/.nyc_output/4db6e0367725f3697aff401f14e83d8e.json +0 -1
  16. package/.nyc_output/51727eb8342f2b80aad8f5cf58247bb8.json +0 -1
  17. package/.nyc_output/53edcbd3a01e01726702fd59ad18528c.json +0 -1
  18. package/.nyc_output/58b1c38b2f1be3dcecbca9bab068a18f.json +0 -1
  19. package/.nyc_output/5c23da3e51b1f6cb82b2337ac4b79674.json +0 -1
  20. package/.nyc_output/6e39c409325db21e0a6645f24d62ea78.json +0 -1
  21. package/.nyc_output/71230f985baca9b3c3a5c96f7db17ce3.json +0 -1
  22. package/.nyc_output/75853f8bad86af123b6ab837115f9154.json +0 -1
  23. package/.nyc_output/79b9684388f3f8d578c0960b2cc38567.json +0 -1
  24. package/.nyc_output/83796d88fa4f05b5616674d83b9ea40a.json +0 -1
  25. package/.nyc_output/9d996c278cdb585d083b6f2cd90514a7.json +0 -1
  26. package/.nyc_output/a5f208db2341f743b5cd29d3fb47f97c.json +0 -1
  27. package/.nyc_output/ae6685d46041b4ede6cc2c43ca0e6021.json +0 -1
  28. package/.nyc_output/b0199893e52a27aa0d6c7ffdc52ae9d1.json +0 -1
  29. package/.nyc_output/d5d71e5d97fce722c611ef2e65170947.json +0 -1
  30. package/.nyc_output/d91d008aa4d6431aa91127a791303d24.json +0 -1
  31. package/.nyc_output/deceb761e61a0f642f51a304fae33d8a.json +0 -1
  32. package/.nyc_output/dfceb102965a150e5812732c638882ef.json +0 -1
  33. package/.nyc_output/e0656fe48b57b517e2c979a8a1578639.json +0 -1
  34. package/.nyc_output/e59e4c5a4d398d7ff45be9f48a01a932.json +0 -1
  35. package/.nyc_output/fecdd97de458efb187320ed600a1253c.json +0 -1
  36. package/tests/browserify-public/.gitkeep +0 -0
  37. package/tests/browserify-public/browserify-bundle.js +0 -43055
  38. package/tests/browserify-public/index.html +0 -2
  39. package/tests/fixtures/browserify-script.js +0 -19
  40. package/tests/fixtures/goodRequest.json +0 -26
  41. package/tests/fixtures/wrongUri.json +0 -50
  42. package/tests/test_abort.js +0 -59
  43. package/tests/test_aws_dynamo.js +0 -39
  44. package/tests/test_back.js +0 -341
  45. package/tests/test_back_2.js +0 -75
  46. package/tests/test_basic_auth.js +0 -79
  47. package/tests/test_body_match.js +0 -68
  48. package/tests/test_browserify.js +0 -54
  49. package/tests/test_common.js +0 -242
  50. package/tests/test_complex_querystring.js +0 -158
  51. package/tests/test_content_encoding.js +0 -26
  52. package/tests/test_data.js +0 -28
  53. package/tests/test_dynamic_mock.js +0 -92
  54. package/tests/test_encode_querystring.js +0 -22
  55. package/tests/test_events.js +0 -63
  56. package/tests/test_gzip_request.js +0 -74
  57. package/tests/test_https_allowunmocked.js +0 -25
  58. package/tests/test_intercept.js +0 -5009
  59. package/tests/test_ipv6.js +0 -55
  60. package/tests/test_isomorphic_fetch.js +0 -104
  61. package/tests/test_net_connect.js +0 -17
  62. package/tests/test_nock_off.js +0 -26
  63. package/tests/test_recorder.js +0 -896
  64. package/tests/test_redirects.js +0 -28
  65. package/tests/test_request_promise.js +0 -25
  66. package/tests/test_s3.js +0 -99
  67. package/tests/test_scope_interceptors.js +0 -11
  68. package/tests/test_timeout.js +0 -21
  69. package/tests/test_url_encoding.js +0 -17
@@ -1,242 +0,0 @@
1
- 'use strict';
2
-
3
- var common = require('../lib/common')
4
- , tap = require('tap')
5
- , matchBody = require('../lib/match_body');
6
-
7
- tap.test('matchBody ignores new line characters from strings', function(t) {
8
- var str1 = "something //here is something more \n";
9
- var str2 = "something //here is something more \n\r";
10
- var matched = matchBody(str1, str2);
11
- t.true(matched);
12
- t.end()
13
- });
14
-
15
- tap.test('matchBody should not throw, when headers come node-fetch style as array', function(t) {
16
- var testThis = {
17
- headers: {
18
- 'Content-Type': ["multipart/form-data;"]
19
- }
20
- }
21
- matchBody.call(testThis, {}, "test");
22
- t.end()
23
- });
24
-
25
- tap.test('matchBody should not ignore new line characters from strings when Content-Type contains \'multipart\'', function(t) {
26
- var str1 = "something //here is something more \nHello";
27
- var str2 = "something //here is something more \nHello";
28
- var testThis = {
29
- headers: {
30
- 'Content-Type': "multipart/form-data;"
31
- }
32
- }
33
- var matched = matchBody.call(testThis, function (body) {
34
- return body === str1;
35
- }, str2);
36
- t.true(matched);
37
- t.end()
38
- });
39
-
40
- tap.test('matchBody should not ignore new line characters from strings when Content-Type contains \'multipart\' (arrays come node-fetch style as array)', function(t) {
41
- var str1 = "something //here is something more \nHello";
42
- var str2 = "something //here is something more \nHello";
43
- var testThis = {
44
- headers: {
45
- 'Content-Type': ["multipart/form-data;"]
46
- }
47
- }
48
- var matched = matchBody.call(testThis, function (body) {
49
- return body === str1;
50
- }, str2);
51
- t.true(matched);
52
- t.end()
53
- });
54
-
55
- tap.test('matchBody uses strict equality for deep comparisons', function(t) {
56
- var spec = { number: 1 };
57
- var body = '{"number": "1"}';
58
- var matched = matchBody(spec, body);
59
- t.false(matched);
60
- t.end()
61
- });
62
-
63
- tap.test('isBinaryBuffer works', function(t) {
64
-
65
- // Returns false for non-buffers.
66
- t.false(common.isBinaryBuffer());
67
- t.false(common.isBinaryBuffer(''));
68
-
69
- // Returns true for binary buffers.
70
- t.true(common.isBinaryBuffer(new Buffer('8001', 'hex')));
71
-
72
- // Returns false for buffers containing strings.
73
- t.false(common.isBinaryBuffer(new Buffer('8001', 'utf8')));
74
-
75
- t.end();
76
-
77
- });
78
-
79
- tap.test('headersFieldNamesToLowerCase works', function(t) {
80
-
81
- var headers = {
82
- 'HoSt': 'example.com',
83
- 'Content-typE': 'plain/text'
84
- };
85
-
86
- var lowerCaseHeaders = common.headersFieldNamesToLowerCase(headers);
87
-
88
- t.equal(headers.HoSt, lowerCaseHeaders.host);
89
- t.equal(headers['Content-typE'], lowerCaseHeaders['content-type']);
90
- t.end();
91
-
92
- });
93
-
94
- tap.test('headersFieldNamesToLowerCase throws on conflicting keys', function(t) {
95
-
96
- var headers = {
97
- 'HoSt': 'example.com',
98
- 'HOST': 'example.com'
99
- };
100
-
101
- try {
102
- common.headersFieldNamesToLowerCase(headers);
103
- } catch(e) {
104
- t.equal(e.toString(), 'Error: Failed to convert header keys to lower case due to field name conflict: host');
105
- t.end();
106
- }
107
-
108
- });
109
-
110
- tap.test('headersFieldsArrayToLowerCase works on arrays', function (t) {
111
- var headers = ['HoSt', 'Content-typE'];
112
-
113
- var lowerCaseHeaders = common.headersFieldsArrayToLowerCase(headers);
114
-
115
- // Order doesn't matter.
116
- lowerCaseHeaders.sort();
117
-
118
- t.deepEqual(lowerCaseHeaders, ['content-type', 'host']);
119
- t.end();
120
- });
121
-
122
- tap.test('headersFieldsArrayToLowerCase deduplicates arrays', function (t) {
123
- var headers = ['hosT', 'HoSt', 'Content-typE', 'conTenT-tYpe'];
124
-
125
- var lowerCaseHeaders = common.headersFieldsArrayToLowerCase(headers);
126
-
127
- // Order doesn't matter.
128
- lowerCaseHeaders.sort();
129
-
130
- t.deepEqual(lowerCaseHeaders, ['content-type', 'host']);
131
- t.end();
132
- });
133
-
134
- tap.test('deleteHeadersField deletes fields with case-insensitive field names', function(t) {
135
-
136
- var headers = {
137
- HoSt: 'example.com',
138
- 'Content-typE': 'plain/text'
139
- };
140
-
141
- t.true(headers.HoSt);
142
- t.true(headers['Content-typE']);
143
-
144
- common.deleteHeadersField(headers, 'HOST');
145
- common.deleteHeadersField(headers, 'CONTENT-TYPE');
146
-
147
- t.false(headers.HoSt);
148
- t.false(headers['Content-typE']);
149
- t.end();
150
-
151
- });
152
-
153
- tap.test('matchStringOrRegexp', function (t) {
154
- t.true(common.matchStringOrRegexp('to match', 'to match'), 'true if pattern is string and target matches');
155
- t.false(common.matchStringOrRegexp('to match', 'not to match'), 'false if pattern is string and target doesn\'t match');
156
-
157
- t.ok(common.matchStringOrRegexp('to match', /match/), 'match if pattern is regex and target matches');
158
- t.false(common.matchStringOrRegexp('to match', /not/), 'false if pattern is regex and target doesn\'t match');
159
- t.end();
160
- });
161
-
162
- tap.test('stringifyRequest', function (t) {
163
- var getMockOptions = function () {
164
- return {
165
- method: "POST",
166
- port: 81,
167
- proto: 'http',
168
- hostname: 'www.example.com',
169
- path: '/path/1',
170
- headers: {
171
- cookie: 'fiz=baz'
172
- }
173
- };
174
- }
175
- var body = {"foo": "bar"};
176
- var postReqOptions = getMockOptions();
177
-
178
- t.equal(common.stringifyRequest(postReqOptions, body),
179
- JSON.stringify({
180
- "method":"POST",
181
- "url":"http://www.example.com:81/path/1",
182
- "headers":{
183
- "cookie": "fiz=baz"
184
- },
185
- "body": {
186
- "foo": "bar"
187
- }
188
- }, null, 2)
189
- );
190
-
191
- var getReqOptions = getMockOptions();
192
- getReqOptions.method = "GET";
193
-
194
- t.equal(common.stringifyRequest(getReqOptions, null),
195
- JSON.stringify({
196
- "method":"GET",
197
- "url":"http://www.example.com:81/path/1",
198
- "headers":{
199
- "cookie": "fiz=baz"
200
- }
201
- }, null, 2)
202
- );
203
-
204
- t.end();
205
- });
206
-
207
-
208
- tap.test('headersArrayToObject', function (t) {
209
- var headers = [
210
- "Content-Type",
211
- "application/json; charset=utf-8",
212
- "Last-Modified",
213
- "foobar",
214
- "Expires",
215
- "fizbuzz"
216
- ];
217
-
218
- t.deepEqual(common.headersArrayToObject(headers), {
219
- "Content-Type": "application/json; charset=utf-8",
220
- "Last-Modified": "foobar",
221
- "Expires": "fizbuzz"
222
- });
223
-
224
- var headersMultipleSetCookies = headers.concat([
225
- "Set-Cookie",
226
- "foo=bar; Domain=.github.com; Path=/",
227
- "Set-Cookie",
228
- "fiz=baz; Domain=.github.com; Path=/"
229
- ]);
230
-
231
- t.deepEqual(common.headersArrayToObject(headersMultipleSetCookies), {
232
- "Content-Type": "application/json; charset=utf-8",
233
- "Last-Modified": "foobar",
234
- "Expires": "fizbuzz",
235
- "Set-Cookie": [
236
- "foo=bar; Domain=.github.com; Path=/",
237
- "fiz=baz; Domain=.github.com; Path=/"
238
- ]
239
- });
240
-
241
- t.end();
242
- });
@@ -1,158 +0,0 @@
1
- var nock = require('../.');
2
- var request = require('request');
3
- var test = require('tap').test;
4
- var http = require('http');
5
-
6
- test('query with array', function(t) {
7
- var query1 = { list: [123, 456, 789], a: 'b' };
8
-
9
- request({
10
- url: 'https://array-query-string.com/test',
11
- qs: query1,
12
- method: 'GET'
13
- }, function(error, response, body) {
14
- t.ok(!error);
15
- t.deepEqual(body, 'success');
16
- t.end();
17
- });
18
-
19
- nock('https://array-query-string.com')
20
- .get('/test')
21
- .query(query1)
22
- .reply(200, 'success');
23
- });
24
-
25
- test('query with array which contains unencoded value ', function(t) {
26
- var query1 = { list: ['hello%20world', '2hello%20world', 3], a: 'b' };
27
-
28
- nock('https://array-query-string.com')
29
- .get('/test')
30
- .query(query1)
31
- .reply(200, 'success');
32
-
33
- request({
34
- url: 'https://array-query-string.com/test',
35
- qs: query1,
36
- method: 'GET'
37
- }, function(error, response, body) {
38
- t.ok(!error);
39
- t.deepEqual(body, 'success');
40
- t.end();
41
- });
42
- });
43
-
44
- test('query with array which contains pre-encoded values ', function(t) {
45
- var query1 = { list: ['hello%20world', '2hello%20world']};
46
-
47
- nock('https://array-query-string.com', { encodedQueryParams: true })
48
- .get('/test')
49
- .query(query1)
50
- .reply(200, 'success');
51
-
52
- request({
53
- url: 'https://array-query-string.com/test?list%5B0%5D=hello%20world&list%5B1%5D=2hello%20world',
54
- method: 'GET'
55
- }, function(error, response, body) {
56
- t.ok(!error);
57
- t.deepEqual(body, 'success');
58
- t.end();
59
- });
60
- });
61
-
62
- test('query with object', function(t) {
63
- var query1 = {
64
- a: {
65
- b: ['c', 'd']
66
- },
67
- e: [1, 2, 3, 4]
68
- };
69
-
70
- nock('https://object-query-string.com')
71
- .get('/test')
72
- .query(query1)
73
- .reply(200, 'success');
74
-
75
- request({
76
- url: 'https://object-query-string.com/test',
77
- qs: query1,
78
- method: 'GET'
79
- }, function(error, response, body) {
80
- t.ok(!error);
81
- t.deepEqual(body, 'success');
82
- t.end();
83
- });
84
- });
85
-
86
- test('query with object which contains unencoded value', function(t) {
87
- var query1 = {
88
- a: {
89
- b: 'hello%20world'
90
- }
91
- };
92
-
93
- nock('https://object-query-string.com')
94
- .get('/test')
95
- .query(query1)
96
- .reply(200, 'success');
97
-
98
- request({
99
- url: 'https://object-query-string.com/test',
100
- qs: query1,
101
- method: 'GET'
102
- }, function(error, response, body) {
103
- t.ok(!error);
104
- t.deepEqual(body, 'success');
105
- t.end();
106
- });
107
- });
108
-
109
- test('query with object which contains pre-encoded values', function(t) {
110
- var query1 = {
111
- a: {
112
- b: 'hello%20world'
113
- }
114
- };
115
-
116
- nock('https://object-query-string.com', { encodedQueryParams: true })
117
- .get('/test')
118
- .query(query1)
119
- .reply(200, 'success');
120
-
121
- request({
122
- url: 'https://object-query-string.com/test?a%5Bb%5D=hello%20world',
123
- method: 'GET'
124
- }, function(error, response, body) {
125
- t.ok(!error);
126
- t.deepEqual(body, 'success');
127
- t.end();
128
- });
129
- });
130
-
131
- test('query with array and regexp', function(t) {
132
- var expectQuery = {
133
- list: [123, 456, 789],
134
- foo: /.*/,
135
- a: 'b'
136
- };
137
-
138
- var actualQuery = {
139
- list: [123, 456, 789],
140
- foo: 'bar',
141
- a: 'b'
142
- };
143
-
144
- nock('https://array-query-string.com')
145
- .get('/test')
146
- .query(expectQuery)
147
- .reply(200, 'success');
148
-
149
- request({
150
- url: 'https://array-query-string.com/test',
151
- qs: actualQuery,
152
- method: 'GET'
153
- }, function(error, response, body) {
154
- t.ok(!error);
155
- t.deepEqual(body, 'success');
156
- t.end();
157
- });
158
- });
@@ -1,26 +0,0 @@
1
- var zlib = require('zlib');
2
- var nock = require('../.');
3
- var http = require('http');
4
- var test = require('tap').test;
5
-
6
- test('accepts gzipped content', {skip: !zlib.gzipSync | !zlib.gunzipSync}, function(t) {
7
- var message = 'Lorem ipsum dolor sit amet';
8
-
9
- var compressedMessage = zlib.gzipSync(message);
10
-
11
- nock('http://gziplandpartywoo')
12
- .get('/foo')
13
- .reply(200, compressedMessage, {
14
- 'X-Transfer-Length': String(compressedMessage.length),
15
- 'Content-Length': undefined,
16
- 'Content-Encoding': 'gzip',
17
- });
18
-
19
- http.get('http://gziplandpartywoo/foo', function(res) {
20
- res.once('data', function(d) {
21
- var dd = zlib.gunzipSync(d);
22
- t.equal(dd.toString(), message);
23
- res.once('end', t.end.bind(t));
24
- });
25
- });
26
- });
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../');
4
- var http = require('http');
5
- var tap = require('tap')
6
-
7
- tap.test('data emits', function(t) {
8
- var reqBody = {data:{message:"hello"}};
9
-
10
- nock("http://api.songkick.com")
11
- .get('/api/3.0/search/venues.json?query=brudenell&apikey=XXXkeyXXX')
12
- .reply(200, reqBody);
13
-
14
- var req = http.get('http://api.songkick.com/api/3.0/search/venues.json?query=brudenell&apikey=XXXkeyXXX', function(res) {
15
- var body = '';
16
-
17
- res.on('data', function(d) {
18
- body += d;
19
- });
20
-
21
- res.on('end', function() {
22
- t.same(JSON.parse(body), reqBody);
23
- t.end();
24
- });
25
-
26
- });
27
-
28
- });
@@ -1,92 +0,0 @@
1
- 'use strict';
2
-
3
- var test = require('tap').test;
4
- var nock = require('../.');
5
- var request = require('request');
6
-
7
- test('one function returning the body defines a full mock', function(t) {
8
- var scope = nock('http://acompleteandfullmock.io')
9
- .get('/abc')
10
- .reply(function() {
11
- return 'ABC';
12
- });
13
-
14
- request.get('http://acompleteandfullmock.io/abc', function(err, resp, body) {
15
- if (err) {
16
- throw err;
17
- }
18
- t.equal(resp.statusCode, 200);
19
- t.equal(body, 'ABC');
20
- t.end();
21
- });
22
- });
23
-
24
- test('one function returning the status code and body defines a full mock', function(t) {
25
- var scope = nock('http://acompleteandfullmock.io')
26
- .get('/def')
27
- .reply(function() {
28
- return [201, 'DEF'];
29
- });
30
-
31
- request.get('http://acompleteandfullmock.io/def', function(err, resp, body) {
32
- if (err) {
33
- throw err;
34
- }
35
- t.equal(resp.statusCode, 201);
36
- t.equal(body, 'DEF');
37
- t.end();
38
- });
39
- });
40
-
41
- test('one asynchronous function returning the status code and body defines a full mock', function(t) {
42
- var scope = nock('http://acompleteandfullmock.io')
43
- .get('/ghi')
44
- .reply(function(path, reqBody, cb) {
45
- setTimeout(function() {
46
- cb(null, [201, 'GHI']);
47
- }, 1e3);
48
-
49
- });
50
-
51
- request.get('http://acompleteandfullmock.io/ghi', function(err, resp, body) {
52
- if (err) {
53
- throw err;
54
- }
55
- t.equal(resp.statusCode, 201);
56
- t.equal(body, 'GHI');
57
- t.end();
58
- });
59
- });
60
-
61
- test('asynchronous function gets request headers', function(t) {
62
- var scope = nock('http://someheadersarein.io')
63
- .get('/yo')
64
- .reply(200, function(path, reqBody, cb) {
65
- t.equal(this.req.path, '/yo');
66
- t.deepEqual(this.req.headers, {
67
- 'x-my-header': 'some-value',
68
- 'x-my-other-header': 'some-other-value',
69
- 'host': 'someheadersarein.io'
70
- });
71
- setTimeout(function() {
72
- cb(null, [201, 'GHI']);
73
- }, 1e3);
74
-
75
- });
76
-
77
- request({
78
- method: 'GET',
79
- uri: 'http://someheadersarein.io/yo',
80
- headers: {
81
- 'x-my-header': 'some-value',
82
- 'x-my-other-header': 'some-other-value'
83
- }}, function(err, resp, body) {
84
- if (err) {
85
- throw err;
86
- }
87
- t.equal(resp.statusCode, 201);
88
- t.equal(body, 'GHI');
89
- t.end();
90
- });
91
-
92
- });
@@ -1,22 +0,0 @@
1
- var nock = require('../.');
2
- var request = require('request');
3
- var test = require('tap').test;
4
-
5
- test('encode query string', function(t) {
6
- var query1 = { q: '(nodejs)' };
7
-
8
- nock('https://encodeland.com')
9
- .get('/test')
10
- .query(query1)
11
- .reply(200, 'success')
12
-
13
- request({
14
- url: 'https://encodeland.com/test',
15
- qs: query1,
16
- method: 'GET'
17
- }, function(error, response, body) {
18
- t.ok(!error);
19
- t.deepEqual(body, 'success');
20
- t.end();
21
- });
22
- });
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../.');
4
- var http = require('http');
5
- var test = require('tap').test;
6
-
7
- test('emits request and replied events', function(t) {
8
- var scope = nock('http://eventland')
9
- .get('/please')
10
- .reply(200);
11
-
12
- scope.on('request', function(req, interceptor) {
13
- t.equal(req.path, '/please');
14
- t.equal(interceptor.interceptionCounter, 0);
15
- scope.on('replied', function(req, interceptor) {
16
- t.equal(req.path, '/please');
17
- t.equal(interceptor.interceptionCounter, 1);
18
- t.end();
19
- });
20
- });
21
-
22
- var req = http.get('http://eventland/please');
23
- });
24
-
25
- test('emits no match when no match and no mock', function(t) {
26
- nock.emitter.once('no match', function(req) {
27
- t.end();
28
- });
29
-
30
- var req = http.get('http://doesnotexistandneverexistedbefore/abc');
31
- req.once('error', ignore);
32
- });
33
-
34
- test('emits no match when no match and mocked', function(t) {
35
-
36
- nock('http://itmayormaynotexistidontknowreally')
37
- .get('/')
38
- .reply('howdy');
39
-
40
-
41
- var assertion = function(req) {
42
- t.equal(req.path, '/definitelymaybe');
43
- nock.emitter.removeAllListeners('no match');
44
- t.end();
45
- }
46
- var result = nock.emitter.on('no match', assertion);
47
-
48
- http.get('http://itmayormaynotexistidontknowreally/definitelymaybe')
49
- .once('error', ignore);
50
- });
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
-
63
- function ignore() {}
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../');
4
- var test = require('tap').test;
5
- var http = require('http');
6
- var assert = require('assert');
7
- var zlib = require('zlib');
8
-
9
- if (zlib.gzipSync && zlib.gunzipSync) {
10
- test('accepts and decodes gzip encoded application/json', function (t) {
11
- var message = {
12
- my: 'contents'
13
- };
14
-
15
- t.plan(1);
16
-
17
- nock('http://gzipped.com')
18
- .post('/')
19
- .reply(function (url, actual) {
20
- t.same(actual, message);
21
- t.end();
22
- return 200
23
- });
24
-
25
- var req = http.request({
26
- hostname: 'gzipped.com',
27
- path: '/',
28
- method: 'POST',
29
- headers: {
30
- 'content-encoding': 'gzip',
31
- 'content-type': 'application/json'
32
- }
33
- });
34
-
35
- var compressedMessage = zlib.gzipSync(JSON.stringify(message));
36
-
37
- req.write(compressedMessage);
38
- req.end();
39
- });
40
- }
41
-
42
- if (zlib.deflateSync && zlib.inflateSync) {
43
-
44
- test('accepts and decodes deflate encoded application/json', function (t) {
45
- var message = {
46
- my: 'contents'
47
- };
48
-
49
- t.plan(1);
50
-
51
- nock('http://gzipped.com')
52
- .post('/')
53
- .reply(function (url, actual) {
54
- t.same(actual, message);
55
- t.end();
56
- return 200
57
- });
58
-
59
- var req = http.request({
60
- hostname: 'gzipped.com',
61
- path: '/',
62
- method: 'POST',
63
- headers: {
64
- 'content-encoding': 'deflate',
65
- 'content-type': 'application/json'
66
- }
67
- });
68
-
69
- var compressedMessage = zlib.deflateSync(JSON.stringify(message));
70
-
71
- req.write(compressedMessage);
72
- req.end();
73
- });
74
- }