Skip to content

Commit

Permalink
test(test_recorder.js): Fix records test
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLitt authored and gr2m committed Dec 14, 2018
1 parent abf7e8f commit cb036b5
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions tests/test_recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,40 @@ test('recording turns off nock interception (backward compatibility behavior)',
});

// Do not copy tests that rely on the process.env.AIRPLANE, we are deprecating that via #1231
test('records', {skip: process.env.AIRPLANE}, function(t) {
test('records', function(t) {
t.plan(5)

nock.restore();
nock.recorder.clear();
t.equal(nock.recorder.play().length, 0);
var options = { method: 'POST'
, host:'google.com'
, port:80
, path:'/' }
;

const server = http.createServer((request, response) => {
t.pass('server received a request')
response.writeHead(200)
response.end()
});

t.once('end', () => {
server.close()
});

nock.recorder.rec(true);
var req = http.request(options, function(res) {
res.resume();
var ret;
res.once('end', function() {
nock.restore();
ret = nock.recorder.play();
server.listen(() => {
const options = {
uri: `https://localhost:${server.address().port}`,
method: 'post'
}

mikealRequest(options, function(err, resp, body) {
nock.restore()
var ret = nock.recorder.play();
t.equal(ret.length, 1);
t.type(ret[0], 'string');
t.equal(ret[0].indexOf("\nnock('https://google.com:80', {\"encodedQueryParams\":true})\n .post('/', \"ABCDEF\")\n .reply("), 0);
t.end();
});
});
req.end('ABCDEF');
});
t.equal(ret[0].indexOf(`\nnock('${options.uri}', {"encodedQueryParams":true})\n .post('/')`), 0);
t.end()
})
})
})

// Do not copy tests that rely on the process.env.AIRPLANE, we are deprecating that via #1231
test('records objects', {skip: process.env.AIRPLANE}, function(t) {
Expand Down

0 comments on commit cb036b5

Please sign in to comment.