Skip to content

Commit

Permalink
tests: passthrough 1077
Browse files Browse the repository at this point in the history
This adds server capabality to allow pass throughts for a couple of intercept tests. See #1077.
  • Loading branch information
RichardLitt committed Dec 14, 2018
1 parent 39e5d92 commit 2dae10d
Showing 1 changed file with 49 additions and 30 deletions.
79 changes: 49 additions & 30 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -2963,42 +2963,61 @@ test("allow unmocked option works with https", function(t) {
})
});

// TODO: remove skip as part of https://github.com/nock/nock/issues/1077
// test('allow unmocked post with json data', {skip: process.env.AIRPLANE}, function(t) {
test('allow unmocked post with json data', {skip: true}, function(t) {
nock('https://httpbin.org', { allowUnmocked: true }).
get("/abc").
reply(200, "Hey!");
test('allow unmocked post with json data', function(t) {
t.plan(2)
t.once('end', function () { server.close() })

var options = {
method: 'POST',
uri: 'https://httpbin.org/post',
json: { some: 'data' }
};
const server = http.createServer((request, response) => {
t.pass('server received a request')
response.writeHead(200)
response.end()
})

mikealRequest(options, function(err, resp, body) {
t.equal(200, resp.statusCode)
t.end();
});
server.listen(() => {
nock(`http:https://localhost:${server.address().port}`, { allowUnmocked: true}).
get('/').
reply(200, "Hey!");


var options = {
method: 'POST',
uri: `http:https://localhost:${server.address().port}`,
json: { some: 'data' }
};

mikealRequest(options, function(err, resp, body) {
t.equal(200, resp.statusCode)
t.end()
})
})
});

// TODO: remove skip as part of https://github.com/nock/nock/issues/1077
// test('allow unmocked passthrough with mismatched bodies', {skip: process.env.AIRPLANE}, function(t) {
test('allow unmocked passthrough with mismatched bodies', {skip: true}, function(t) {
nock('http:https://httpbin.org', { allowUnmocked: true }).
post("/post", {some: 'otherdata'}).
reply(404, "Hey!");
test('allow unmocked passthrough with mismatched bodies', function(t) {
t.plan(2)
t.once('end', function () { server.close() })

var options = {
method: 'POST',
uri: 'http:https://httpbin.org/post',
json: { some: 'data' }
};
const server = http.createServer((request, response) => {
t.pass('server received a request')
response.writeHead(200)
response.end()
})

mikealRequest(options, function(err, resp, body) {
t.equal(200, resp.statusCode)
t.end();
});
server.listen(() => {
nock(`http:https://localhost:${server.address().port}`, { allowUnmocked: true}).
post("/post", {some: 'otherdata'}).
reply(404, "Hey!");

var options = {
method: 'POST',
uri: `http:https://localhost:${server.address().port}/post`,
json: { some: 'data' }
};

mikealRequest(options, function(err, resp, body) {
t.equal(200, resp.statusCode)
t.end()
});
})
});

test('allow unordered body with json encoding', function(t) {
Expand Down

0 comments on commit 2dae10d

Please sign in to comment.