Skip to content

Commit

Permalink
NOCK_OFF environment variable set to true bypasses nock
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed May 12, 2012
1 parent 972b1f4 commit 40b27d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -237,6 +237,14 @@ You can restore the HTTP interceptor to the normal unmocked behaviour by calling

nock.restore();

# Turning Nock Off

You can bypass Nock completely by setting `NOCK_OFF` environment variable to `"true"`.

This way you can have your tests hit the real servers just by switching on this environment variable.

$ NOCK_OFF=true node my_test.js

# Recording

This is a cool feature:
Expand Down
8 changes: 7 additions & 1 deletion lib/intercept.js
Expand Up @@ -6,8 +6,13 @@ var RequestOverrider = require('./request_overrider'),
http = require('http'),
ClientRequest = http.ClientRequest;


var allInterceptors = {};

function isOn() {
return process.env.NOCK_OFF !== 'true';
}

function add(key, interceptor) {
if (! allInterceptors.hasOwnProperty(key)) {
allInterceptors[key] = [];
Expand Down Expand Up @@ -91,7 +96,7 @@ http.ClientRequest = OverridenClientRequest;
options.proto = proto;
interceptors = interceptorsFor(options);

if (interceptors.length) {
if (isOn() && interceptors.length) {

var matches = false,
allowUnmocked = false;
Expand Down Expand Up @@ -123,3 +128,4 @@ http.ClientRequest = OverridenClientRequest;

module.exports = add;
module.exports.removeAll = removeAll;
module.exports.isOn = isOn;
6 changes: 5 additions & 1 deletion lib/scope.js
Expand Up @@ -3,7 +3,7 @@ var path = require('path')
, globalIntercept = require('./intercept')
, mixin = require('./mixin')
, assert = require('assert')
, url = require('url');
, url = require('url');

var noop = function() {};

Expand Down Expand Up @@ -210,6 +210,10 @@ function startScope(basePath, options) {
}

function isDone() {

// if nock is turned off, it always says it's done
if (! globalIntercept.isOn()) { return true; }

var keys = Object.keys(interceptors);
if (keys.length === 0) {
return true;
Expand Down

0 comments on commit 40b27d5

Please sign in to comment.