-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1277 from nock/1077/remove-airplane-mode-from-tes…
…t_knock_off remove AIRPLANE mode from test_nock_off
- Loading branch information
Showing
1 changed file
with
34 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |