Socket
Socket
Sign inDemoInstall

nock

Package Overview
Dependencies
Maintainers
1
Versions
430
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nock - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

lib/recorder.js

10

index.js

@@ -1,1 +0,9 @@

module.exports = require('./lib/scope');
var recorder = require('./lib/recorder')
module.exports = require('./lib/scope');
module.exports.recorder = {
rec : recorder.record
, clear : recorder.clear
, play : recorder.outputs
};
module.exports.restore = recorder.restore;

@@ -135,2 +135,3 @@ var path = require('path')

console.log('interceptors length:', interceptors.length);
if (interceptors.length < 1) { throw new Error("Nock: No match for HTTP request " + stringifyRequest(options)); }

@@ -137,0 +138,0 @@ interceptor = interceptors.shift();

2

lib/scope.js

@@ -27,3 +27,3 @@ var path = require('path')

arr.splice(arr.indexOf(interceptor), 1);
if (arr.length === 0) { delete interceptors[key]; }
if (arr.length === 0) { console.log('deleting interceptor for ', key); delete interceptors[key]; }
}

@@ -30,0 +30,0 @@ }

{ "name" : "nock"
, "description" : "HTTP Server mocking for Node.js"
, "tags" : ["Mock", "HTTP", "testing", "isolation"]
, "version" : "0.4.0"
, "version" : "0.5.0"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>"
, "contributors" :
[ "Roly Fentanes"
, "Alexander Simmerl"
[ {"name":"Roly Fentanes" }
, {"name":"Alexander Simmerl"}
, {"name":"Pedro Teixeira"}
]

@@ -10,0 +11,0 @@ , "repository" :

@@ -165,5 +165,48 @@ # Nock

...
# Restoring
You can restore the HTTP interceptor to the normal unmocked behaviour by calling:
nock.restore();
# Recording
This is a cool feature:
Guessing what the HTTP calls are is a mess, specially if you are introducing nock on your already-coded tests.
For these cases where you want to mock an existing live system you can record and playback the HTTP calls like this:
nock.recorder.rec();
// Some HTTP calls happen and the nock code necessary to mock
// those calls will be outputted to console
If you just want to capture the generated code into a var as an array you can use:
nock.recorder.rec(true); // :no_output = true
// ... some HTTP calls
var nockCalls = nock.recorder.play();
The `nockCalls` var will contain an array of strings representing the generated code you need.
Copy and paste that code into your tests, customize at will, and you're done!
(Remember that you should do this one test at a time).
# How does it work?
Nock works by overriding Node's http.request function.
Nock works by overriding Node's http.request function.
# License
(The MIT License)
Copyright (c) 2011 Pedro Teixeira. http://about.me/pedroteixeira
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FUCK YEAH.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc