Skip to content

Commit

Permalink
Merge pull request #1277 from nock/1077/remove-airplane-mode-from-tes…
Browse files Browse the repository at this point in the history
…t_knock_off

remove AIRPLANE mode from test_nock_off
  • Loading branch information
RichardLitt committed Dec 14, 2018
2 parents 19d8c6d + db44b4d commit abf7e8f
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions tests/test_nock_off.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
'use strict';

var test = require('tap').test;
var test = require('tap').test;
var mikealRequest = require('request');

var ssl = require('./ssl')

// Do not copy tests that rely on the process.env.AIRPLANE, we are deprecating that via #1231
test('NOCK_OFF=true works for https', {skip: process.env.AIRPLANE}, function(t) {
test('NOCK_OFF=true works for https', function (t) {
var original = process.env.NOCK_OFF;
process.env.NOCK_OFF = 'true';
var nock = require('../');
var scope = nock('https://www.google.com')
.get('/')
.reply(200, {foo: 'bar'});

var options = {
method: 'GET',
uri: 'https://www.google.com'
};

mikealRequest(options, function(err, resp, body) {
t.notOk(err);
t.notDeepEqual(body, '{"foo":"bar"}');
scope.done();
process.env.NOCK_OFF = original;
t.end();

t.plan(4);

function middleware (request, response) {
t.pass('server received a request');
response.writeHead(200);
response.end('the real thing');
}

ssl.startServer(middleware, function (error, server) {
t.error(error);

var port = server.address().port
var scope = nock(`https://localhost:${port}`, { allowUnmocked: true})
.get('/')
.reply(200, 'mock')

var options = {
method: 'GET',
uri: `https://localhost:${port}`,
ca: ssl.ca
};

mikealRequest(options, function (err, resp, body) {
t.error(err);
t.equal(body, 'the real thing');
scope.done();
process.env.NOCK_OFF = original;
server.close(t.end);
});
});
});

0 comments on commit abf7e8f

Please sign in to comment.