diff --git a/lib/request_overrider.js b/lib/request_overrider.js index 528505466..797160d05 100644 --- a/lib/request_overrider.js +++ b/lib/request_overrider.js @@ -159,6 +159,16 @@ function RequestOverrider(req, options, interceptors, remove, cb) { } }; + req.flushHeaders = function() { + debug('req.flushHeaders'); + if (!aborted && !ended) { + end(cb); + } + if (aborted) { + emitError(new Error('Request aborted')); + } + }; + req.abort = function() { if (aborted) { return; diff --git a/tests/test_common.js b/tests/test_common.js index c5b2662f4..98931ba50 100644 --- a/tests/test_common.js +++ b/tests/test_common.js @@ -157,7 +157,7 @@ tap.test('deleteHeadersField deletes fields with case-insensitive field names', }); -tap.test('matchStringOrRegexp', {only: true}, function (t) { +tap.test('matchStringOrRegexp', function (t) { t.true(common.matchStringOrRegexp('to match', 'to match'), 'true if pattern is string and target matches'); t.false(common.matchStringOrRegexp('to match', 'not to match'), 'false if pattern is string and target doesn\'t match'); diff --git a/tests/test_intercept.js b/tests/test_intercept.js index 5ffafe242..dbc83341b 100644 --- a/tests/test_intercept.js +++ b/tests/test_intercept.js @@ -61,7 +61,7 @@ test("allow unmocked works (2)", function(t) { }); }); -test("allow unmocked works after one interceptor is removed", {only: true}, function(t) { +test("allow unmocked works after one interceptor is removed", function(t) { nock("https://example.org",{allowUnmocked: true}). get("/"). reply(200, "Mocked"); @@ -72,9 +72,6 @@ test("allow unmocked works after one interceptor is removed", {only: true}, func mikealRequest("https://example.org/unmocked", function(err, resp, body) { t.error(err); - console.log(`\nbody ==============================`) - console.log(body) - t.assert(~body.indexOf('Example Domain')); t.end(); }); @@ -5235,6 +5232,25 @@ test('correctly parse request without specified path (#1003)', function(t) { }).end(); }); +test('data is sent with flushHeaders', function(t) { + nock.cleanAll(); + + var scope1 = nock('https://example.com') + .get('') + .reply(200, 'this is data'); + + https.request({hostname: 'example.com'}, function(res) { + t.equal(res.statusCode, 200); + res.on('data', function(data) { + t.equal(data.toString(), 'this is data'); + }); + res.on('end', function() { + scope1.done(); + t.end(); + }); + }).flushHeaders(); +}); + test("teardown", function(t) { var leaks = Object.keys(global) .splice(globalCount, Number.MAX_VALUE);