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,59 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../.');
4
- var http = require('http');
5
- var test = require('tap').test;
6
-
7
- function assertEvents(t, cb) {
8
- var gotAbort = false
9
- var req = http.get('http://localhost:16829/status')
10
- .once('abort', function () {
11
- // Should trigger first
12
- gotAbort = true
13
- })
14
- .once('error', function (err) {
15
- // Should trigger last
16
- t.equal(err.code, 'ECONNRESET')
17
- t.ok(gotAbort, 'didn\'t get abort event');
18
- t.end();
19
- if(cb) {
20
- cb();
21
- }
22
- });
23
-
24
- process.nextTick(function(){
25
- req.abort();
26
- });
27
- }
28
-
29
- test('[actual] req.abort() should cause "abort" and "error" to be emitted', function (t) {
30
- nock('http://localhost:16829')
31
- .get('/status')
32
- .delayConnection(500)
33
- .reply(204);
34
-
35
- assertEvents(t);
36
- });
37
-
38
- test("abort is emitted before delay time", function(t) {
39
- nock('http://test.example.com')
40
- .get('/status')
41
- .delayConnection(500)
42
- .reply(204);
43
-
44
- var tstart = Date.now();
45
- var req = http.get('http://test.example.com/status')
46
- // Don't bother with the response
47
- .once('abort', function() {
48
- var actual = Date.now() - tstart;
49
- t.ok(actual < 250, 'abort took only ' + actual + ' ms');
50
- t.end();
51
- })
52
- .once('error', function(err) {
53
- // don't care
54
- });
55
-
56
- setTimeout(function() {
57
- req.abort();
58
- }, 10);
59
- });
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../');
4
- var AWS = require('aws-sdk');
5
- var test = require('tap').test;
6
-
7
- test('works with dynamodb', function(t) {
8
- var done = false;
9
- var REGION = 'us-east-1';
10
-
11
- AWS.config.update({
12
- 'region': REGION,
13
- 'sslEnabled': true,
14
- 'accessKeyId': 'ACCESSKEYID',
15
- 'secretAccessKey': 'SECRETACCESSKEY'
16
- });
17
-
18
- var db = new AWS.DynamoDB();
19
-
20
- nock('https://dynamodb.' + REGION + '.amazonaws.com')
21
- .post('/')
22
- .reply(200, {});
23
-
24
- db.getItem(
25
- {
26
- Key: {
27
- Artist: {
28
- S: 'Lady Gaga'
29
- }
30
- },
31
- TableName: 'Music'
32
- },
33
- function(err, resp) {
34
- if (err) throw err;
35
- t.deepEqual(resp, {});
36
- t.end();
37
- });
38
- });
39
-
@@ -1,341 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../.')
4
- , nockBack= nock.back
5
- , tap = require('tap')
6
- , http = require('http')
7
- , fs = require('fs')
8
- , exists = fs.existsSync;
9
-
10
- nock.enableNetConnect();
11
-
12
- var originalMode = nockBack.currentMode;
13
-
14
- function testNock (t) {
15
- var dataCalled = false;
16
-
17
- var scope = nock('http://www.google.com')
18
- .get('/')
19
- .reply(200, "Hello World!");
20
-
21
- var req = http.request({
22
- host: "www.google.com"
23
- , path: '/'
24
- , port: 80
25
- }, function(res) {
26
-
27
- t.equal(res.statusCode, 200);
28
- res.once('end', function() {
29
- t.ok(dataCalled);
30
- scope.done();
31
- t.end();
32
- });
33
- res.on('data', function(data) {
34
- dataCalled = true;
35
- t.ok(data instanceof Buffer, "data should be buffer");
36
- t.equal(data.toString(), "Hello World!", "response should match");
37
- });
38
- });
39
-
40
- req.end();
41
- }
42
-
43
- function nockBackWithFixture (t, scopesLoaded) {
44
- var scopesLength = scopesLoaded ? 1 : 0;
45
-
46
- nockBack('goodRequest.json', function (done) {
47
- t.true(this.scopes.length === scopesLength);
48
- http.get('http://www.google.com').end();
49
- this.assertScopesFinished();
50
- done();
51
- t.end();
52
- });
53
- }
54
-
55
- function setOriginalModeOnEnd(t, nockBack) {
56
- t.once('end', function() {
57
- nockBack.setMode(originalMode);
58
- });
59
- }
60
-
61
- tap.test('nockBack throws an exception when fixtures is not set', function (t) {
62
-
63
- try {
64
- nockBack();
65
- } catch (e) {
66
- t.ok(true, 'excpected exception');
67
- t.end();
68
- return;
69
- }
70
-
71
- t.fail(true, false, 'test should have ended');
72
-
73
- });
74
-
75
- tap.test('nockBack wild tests', function (nw) {
76
-
77
- // Manually disable net connectivity to confirm that dryrun enables it.
78
- nock.disableNetConnect();
79
-
80
- nockBack.fixtures = __dirname + '/fixtures';
81
- nockBack.setMode('wild');
82
-
83
- nw.test('normal nocks work', function (t) {
84
- testNock(t);
85
- });
86
-
87
- nw.test('nock back doesn\'t do anything', {skip: process.env.AIRPLANE}, function (t) {
88
- nockBackWithFixture(t, false);
89
- });
90
-
91
- setOriginalModeOnEnd(nw, nockBack);
92
-
93
- nw.end();
94
- });
95
-
96
- tap.test('nockBack dryrun tests', function (nw) {
97
-
98
- // Manually disable net connectivity to confirm that dryrun enables it.
99
- nock.disableNetConnect();
100
-
101
- nockBack.fixtures = __dirname + '/fixtures';
102
- nockBack.setMode('dryrun');
103
-
104
- nw.test('goes to internet even when no nockBacks are running', {skip: process.env.AIRPLANE}, function(t) {
105
- var req = http.request({
106
- host: "www.amazon.com"
107
- , path: '/'
108
- , port: 80
109
- }, function(res) {
110
-
111
- res.on('data', function() {
112
- //node v 0.10 requires this listener
113
- });
114
- t.ok([200, 301, 302].indexOf(res.statusCode) >= 0);
115
- t.end();
116
-
117
- });
118
-
119
- req.on('error', function(err) {
120
-
121
- // This should never happen.
122
- t.assert(false);
123
- t.end();
124
-
125
- });
126
-
127
- req.end();
128
- });
129
-
130
- nw.test('normal nocks work', function (t) {
131
- testNock(t);
132
- });
133
-
134
- nw.test('uses recorded fixtures', function (t) {
135
- nockBackWithFixture(t, true);
136
- });
137
-
138
- nw.test('goes to internet, doesn\'t record new fixtures', {skip: process.env.AIRPLANE}, function (t) {
139
- var dataCalled = false;
140
-
141
- var fixture = 'someDryrunFixture.json';
142
- var fixtureLoc = nockBack.fixtures + '/' + fixture;
143
-
144
- t.false(exists(fixtureLoc));
145
-
146
- nockBack(fixture, function (done) {
147
- var req = http.request({
148
- host: "www.amazon.com"
149
- , path: '/'
150
- , port: 80
151
- }, function(res) {
152
-
153
- t.ok([200, 301, 302].indexOf(res.statusCode) >= 0);
154
- res.on('end', function() {
155
- var doneFails = false;
156
-
157
- t.ok(dataCalled);
158
- try {
159
- done();
160
- t.false(exists(fixtureLoc));
161
- scope.done();
162
- } catch(err) {
163
- doneFails = true;
164
- }
165
- t.ok(doneFails);
166
- t.end();
167
- });
168
-
169
- res.on('data', function(data) {
170
- dataCalled = true;
171
- });
172
-
173
- });
174
-
175
- req.once('error', function(err) {
176
- if (err.code !== 'ECONNREFUSED') {
177
- throw err;
178
- }
179
- t.end();
180
- });
181
-
182
- req.end();
183
- });
184
- });
185
-
186
- setOriginalModeOnEnd(nw, nockBack);
187
-
188
- nw.end();
189
- });
190
-
191
- tap.test('nockBack record tests', function (nw) {
192
- nockBack.setMode('record');
193
-
194
- nw.test('it records when configured correctly', {skip: process.env.AIRPLANE}, function (t) {
195
- nockBack.fixtures = __dirname + '/fixtures';
196
-
197
- var options = {
198
- host: 'www.google.com', method: 'GET', path: '/', port: 80
199
- };
200
-
201
- var fixture = 'someFixture.json';
202
- var fixtureLoc = nockBack.fixtures + '/' + fixture;
203
-
204
- t.false(exists(fixtureLoc));
205
-
206
- nockBack(fixture, function (done) {
207
- http.request(options).end();
208
- done();
209
-
210
- t.true(exists(fixtureLoc));
211
-
212
- fs.unlinkSync(fixtureLoc);
213
- t.end();
214
- });
215
-
216
- });
217
-
218
- //Adding this test because there was an issue when not calling
219
- //nock.activate() after calling nock.restore()
220
- nw.test('it can record twice', {skip: process.env.AIRPLANE}, function (t) {
221
- nockBack.fixtures = __dirname + '/fixtures';
222
-
223
- var options = {
224
- host: 'www.google.com', method: 'GET', path: '/', port: 80
225
- };
226
- var fixture = 'someFixture2.json';
227
- var fixtureLoc = nockBack.fixtures + '/' + fixture;
228
- t.false(exists(fixtureLoc));
229
-
230
- nockBack(fixture, function (done) {
231
- http.request(options).end();
232
- done();
233
-
234
- t.true(exists(fixtureLoc));
235
-
236
- fs.unlinkSync(fixtureLoc);
237
- t.end();
238
- });
239
-
240
- });
241
-
242
- nw.test('it shouldn\'t allow outside calls', function (t) {
243
-
244
- var fixture = 'wrongUri.json';
245
-
246
- nockBack(fixture, function (done) {
247
-
248
- http.get('http://www.amazon.com', function(res) {
249
- throw "should not request this";
250
- }).on('error', function(err) {
251
- t.equal(err.message, 'Nock: Not allow net connect for "www.amazon.com:80/"');
252
- done();
253
- t.end();
254
- });
255
-
256
- });
257
-
258
- });
259
-
260
- nw.test('it loads your recorded tests', function (t) {
261
-
262
- nockBack('goodRequest.json', function (done) {
263
- t.true(this.scopes.length > 0);
264
- http.get('http://www.google.com').end();
265
- this.assertScopesFinished();
266
- done();
267
- t.end();
268
- });
269
-
270
- });
271
-
272
- nw.test('it can filter after recording', {skip: process.env.AIRPLANE}, function (t) {
273
- nockBack.fixtures = __dirname + '/fixtures';
274
-
275
- var options = {
276
- host: 'www.google.com', method: 'GET', path: '/', port: 80
277
- };
278
-
279
- var fixture = 'filteredFixture.json';
280
- var fixtureLoc = nockBack.fixtures + '/' + fixture;
281
-
282
- t.false(exists(fixtureLoc));
283
-
284
- var afterRecord = function(scopes) {
285
- // You would do some filtering here, but for this test we'll just return an empty array
286
- return [];
287
- }
288
-
289
- nockBack(fixture, {afterRecord: afterRecord}, function (done) {
290
- http.request(options).end();
291
- done();
292
-
293
- t.true(exists(fixtureLoc));
294
-
295
- nockBack(fixture, function (done) {
296
- t.true(this.scopes.length === 0);
297
- done();
298
-
299
- fs.unlinkSync(fixtureLoc);
300
- t.end();
301
- });
302
- });
303
- });
304
-
305
- nw.end();
306
-
307
- setOriginalModeOnEnd(nw, nockBack);
308
- });
309
-
310
- tap.test('nockBack lockdown tests', function (nw) {
311
- nockBack.fixtures = __dirname + '/fixtures';
312
- nockBack.setMode('lockdown');
313
-
314
- nw.test('normal nocks work', function (t) {
315
- testNock(t);
316
- });
317
-
318
- nw.test('nock back loads scope', function (t) {
319
- nockBackWithFixture(t, true);
320
- });
321
-
322
- nw.test('no unnocked http calls work', function (t) {
323
- var req = http.request({
324
- host: "google.com"
325
- , path: '/'
326
- }, function(res) {
327
- throw new Error('should not come here!');
328
- });
329
-
330
- req.on('error', function (err) {
331
- t.equal(err.message.trim(), 'Nock: Not allow net connect for "google.com:80/"');
332
- t.end();
333
- });
334
-
335
- req.end();
336
- });
337
-
338
- setOriginalModeOnEnd(nw, nockBack);
339
-
340
- nw.end();
341
- });
@@ -1,75 +0,0 @@
1
- 'use strict';
2
-
3
- var test = require('tap').test;
4
- var nock = require('../');
5
- var nockBack = nock.back;
6
- var http = require("http");
7
- var rimraf = require('rimraf');
8
- var fs = require('fs');
9
-
10
- var originalMode;
11
- var fixture;
12
-
13
- function rimrafOnEnd(t) {
14
- t.once('end', function() {
15
- rimraf.sync(fixture);
16
- });
17
- }
18
-
19
- test('setup', function(t) {
20
- originalMode = nockBack.currentMode;
21
-
22
- nock.enableNetConnect();
23
- nockBack.fixtures = __dirname + "/fixtures";
24
- fixture = nockBack.fixtures + '/recording_test.json'
25
- rimraf.sync(fixture);
26
-
27
- nockBack.setMode("record");
28
- t.end();
29
- });
30
-
31
- test('recording', {skip: process.env.AIRPLANE}, function(t) {
32
- nockBack('recording_test.json', function(nockDone) {
33
- http.get('http://google.com', function(res) {
34
- res.once('end', function() {
35
- nockDone();
36
- var fixtureContent = JSON.parse(fs.readFileSync(fixture, {encoding: 'utf8'}));
37
- t.equal(fixtureContent.length, 1);
38
- fixtureContent = fixtureContent[0];
39
- t.equal(fixtureContent.method, 'GET');
40
- t.equal(fixtureContent.path, '/');
41
- t.ok(fixtureContent.status == 302 || fixtureContent.status == 301);
42
- t.end();
43
- });
44
- // Streams start in 'paused' mode and must be started.
45
- // See https://nodejs.org/api/stream.html#stream_class_stream_readable
46
- res.resume();
47
- });
48
- });
49
-
50
- rimrafOnEnd(t);
51
- });
52
-
53
- test('passes custom options to recorder', {skip: process.env.AIRPLANE}, function(t) {
54
- nockBack('recording_test.json', { recorder: { enable_reqheaders_recording: true } }, function(nockDone) {
55
- http.get('http://google.com', function(res) {
56
- res.once('end', function() {
57
- nockDone();
58
- var fixtureContent = JSON.parse(fs.readFileSync(fixture, {encoding: 'utf8'}));
59
- t.equal(fixtureContent.length, 1);
60
- fixtureContent = fixtureContent[0];
61
- t.ok(fixtureContent.reqheaders);
62
- t.end();
63
- });
64
- // Streams start in 'paused' mode and must be started.
65
- // See https://nodejs.org/api/stream.html#stream_class_stream_readable
66
- res.resume();
67
- });
68
- });
69
- rimrafOnEnd(t);
70
- });
71
-
72
- test('teardown', function(t) {
73
- nockBack.setMode(originalMode);
74
- t.end();
75
- });
@@ -1,79 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../');
4
- var request = require('request');
5
- var test = require('tap').test;
6
-
7
- test('basic auth with username and password', function(t) {
8
- t.plan(2);
9
-
10
- nock('http://super-secure.com')
11
- .get('/test')
12
- .basicAuth({
13
- user: 'foo',
14
- pass: 'bar'
15
- })
16
- .reply(200, 'Here is the content');
17
-
18
- t.test('succeeds when it matches', function (tt) {
19
- request({
20
- url: 'http://super-secure.com/test',
21
- auth: {
22
- user: 'foo',
23
- pass: 'bar'
24
- }
25
- }, function(err, res, body) {
26
- if (err) {
27
- throw err;
28
- }
29
- tt.equal(res.statusCode, 200);
30
- tt.equal(body, 'Here is the content');
31
- tt.end();
32
- });
33
- });
34
-
35
- t.test('fails when it doesnt match', function (tt) {
36
- request({
37
- url: 'http://super-secure.com/test',
38
- }, function(err, res, body) {
39
- tt.type(err, 'Error');
40
- tt.end();
41
- });
42
- });
43
- });
44
-
45
- test('basic auth with username only', function(t) {
46
- t.plan(2);
47
-
48
- nock('http://super-secure.com')
49
- .get('/test')
50
- .basicAuth({
51
- user: 'foo'
52
- })
53
- .reply(200, 'Here is the content');
54
-
55
- t.test('succeeds when it matches', function (tt) {
56
- request({
57
- url: 'http://super-secure.com/test',
58
- auth: {
59
- user: 'foo'
60
- }
61
- }, function(err, res, body) {
62
- if (err) {
63
- throw err;
64
- }
65
- tt.equal(res.statusCode, 200);
66
- tt.equal(body, 'Here is the content');
67
- tt.end();
68
- });
69
- });
70
-
71
- t.test('fails when it doesnt match', function (tt) {
72
- request({
73
- url: 'http://super-secure.com/test',
74
- }, function(err, res, body) {
75
- tt.type(err, 'Error');
76
- tt.end();
77
- });
78
- });
79
- });
@@ -1,68 +0,0 @@
1
- 'use strict';
2
-
3
- var nock = require('../');
4
- var test = require('tap').test;
5
- var mikealRequest = require('request');
6
- var assert = require('assert');
7
-
8
- test('match body with regex', function (t) {
9
-
10
- nock('http://encodingsareus.com')
11
- .post('/', {auth: {passwd: /a.+/}})
12
- .reply(200);
13
-
14
- mikealRequest({
15
- url: 'http://encodingsareus.com/',
16
- method: 'post',
17
- json: {
18
- auth: {
19
- passwd: 'abc'
20
- }
21
- },
22
- }, function(err, res) {
23
- if (err) throw err;
24
- assert.equal(res.statusCode, 200);
25
- t.end();
26
- });
27
-
28
- });
29
-
30
- test('match body with regex inside array', function (t) {
31
-
32
- nock('http://encodingsareus.com')
33
- .post('/', {items: [{name: /t.+/}]})
34
- .reply(200);
35
-
36
- mikealRequest({
37
- url: 'http://encodingsareus.com/',
38
- method: 'post',
39
- json: {
40
- items: [{
41
- name: 'test'
42
- }]
43
- },
44
- }, function(err, res) {
45
- if (err) throw err;
46
- assert.equal(res.statusCode, 200);
47
- t.end();
48
- });
49
- })
50
-
51
- test('match body with empty object inside', function (t) {
52
-
53
- nock('http://encodingsareus.com')
54
- .post('/', { obj: {}})
55
- .reply(200);
56
-
57
- mikealRequest({
58
- url: 'http://encodingsareus.com/',
59
- method: 'post',
60
- json: {
61
- obj: {}
62
- },
63
- }, function(err, res) {
64
- if (err) throw err;
65
- assert.equal(res.statusCode, 200);
66
- t.end();
67
- });
68
- })
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('fs');
4
- var path = require('path');
5
- var http = require('http');
6
- var browserify = require('browserify');
7
- var Static = require('node-static');
8
- var Browser = require('zombie');
9
-
10
- var test = require('tap').test;
11
- var before = test;
12
- var after = test;
13
-
14
- var nock = require('../.');
15
-
16
- nock.enableNetConnect();
17
-
18
- var server;
19
-
20
- before('prepare bundle', {timeout: 10000}, function(t) {
21
- var b = browserify();
22
- b.add(path.join(__dirname, 'fixtures', 'browserify-script.js'));
23
- b.bundle().pipe(fs.createWriteStream(path.join(__dirname, 'browserify-public', 'browserify-bundle.js'))).once('finish', function() {
24
- t.end();
25
- });
26
- });
27
-
28
- before('start server', function(t) {
29
- var file = new Static.Server(path.join(__dirname, 'browserify-public'));
30
- server = http.createServer(function(req, res) {
31
- file.serve(req, res);
32
- });
33
-
34
- server.listen(8080, t.end.bind(t));
35
- });
36
-
37
- test('run bundle', function(t) {
38
- Browser.localhost('server.com', 8080);
39
-
40
- var browser = new Browser();
41
-
42
- browser.on('error', function(err) {
43
- console.error('BROWSER ERROR: ' + err.stack);
44
- });
45
-
46
- browser.visit('/', function() {
47
- browser.assert.text('#content', 'boop');
48
- t.end();
49
- });
50
- });
51
-
52
- after('stop server', function(t) {
53
- server.close(t.end.bind(t));
54
- });