+15
-0
@@ -185,3 +185,15 @@ var path = require('path') | ||
| } | ||
| function once() { | ||
| return this.times(1); | ||
| } | ||
| function twice() { | ||
| return this.times(2); | ||
| } | ||
| function thrice() { | ||
| return this.times(3); | ||
| } | ||
| var interceptor = { | ||
@@ -199,2 +211,5 @@ _key: key | ||
| , times: times | ||
| , once: once | ||
| , twice: twice | ||
| , thrice: thrice | ||
| }; | ||
@@ -201,0 +216,0 @@ |
+1
-1
| { "name" : "nock" | ||
| , "description" : "HTTP Server mocking for Node.js" | ||
| , "tags" : ["Mock", "HTTP", "testing", "isolation"] | ||
| , "version" : "0.21.0" | ||
| , "version" : "0.22.0" | ||
| , "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : |
+11
-1
@@ -152,9 +152,19 @@ # Nock [](http://travis-ci.org/flatiron/nock) | ||
| ```js | ||
| nock('http://zombo.com').get('/').times(2).reply(200, 'Ok'); | ||
| nock('http://zombo.com').get('/').times(4).reply(200, 'Ok'); | ||
| http.get('http://zombo.com/'); // respond body "Ok" | ||
| http.get('http://zombo.com/'); // respond body "Ok" | ||
| http.get('http://zombo.com/'); // respond body "Ok" | ||
| http.get('http://zombo.com/'); // respond body "Ok" | ||
| http.get('http://zombo.com/'); // respond with zombo.com result | ||
| ``` | ||
| Sugar sintaxe | ||
| ```js | ||
| nock('http://zombo.com').get('/').once().reply(200, 'Ok'); | ||
| nock('http://zombo.com').get('/').twice().reply(200, 'Ok'); | ||
| nock('http://zombo.com').get('/').thrice().reply(200, 'Ok'); | ||
| ``` | ||
| ## Chaining | ||
@@ -161,0 +171,0 @@ |
@@ -1859,3 +1859,3 @@ var nock = require('../.') | ||
| test('repeating response 2 times', function(t) { | ||
| test('repeating once', function(t) { | ||
| nock.disableNetConnect(); | ||
@@ -1865,12 +1865,28 @@ | ||
| .get('/') | ||
| .times(2) | ||
| .once() | ||
| .reply(200, "Hello World!"); | ||
| http.get('http://zombo.com', function(res) { | ||
| t.equal(200, res.statusCode, 'first request'); | ||
| }); | ||
| nock.cleanAll() | ||
| t.end(); | ||
| http.get('http://zombo.com', function(res) { | ||
| t.equal(200, res.statusCode, 'second request'); | ||
| }); | ||
| nock.enableNetConnect(); | ||
| }); | ||
| test('repeating twice', function(t) { | ||
| nock.disableNetConnect(); | ||
| var _mock = nock('http://zombo.com') | ||
| .get('/') | ||
| .twice() | ||
| .reply(200, "Hello World!"); | ||
| for (var i=0; i < 2; i++) { | ||
| http.get('http://zombo.com', function(res) { | ||
| t.equal(200, res.statusCode, 'first request'); | ||
| }); | ||
| }; | ||
@@ -1882,1 +1898,41 @@ nock.cleanAll() | ||
| }); | ||
| test('repeating thrice', function(t) { | ||
| nock.disableNetConnect(); | ||
| var _mock = nock('http://zombo.com') | ||
| .get('/') | ||
| .thrice() | ||
| .reply(200, "Hello World!"); | ||
| for (var i=0; i < 3; i++) { | ||
| http.get('http://zombo.com', function(res) { | ||
| t.equal(200, res.statusCode, 'first request'); | ||
| }); | ||
| }; | ||
| nock.cleanAll() | ||
| t.end(); | ||
| nock.enableNetConnect(); | ||
| }); | ||
| test('repeating response 4 times', function(t) { | ||
| nock.disableNetConnect(); | ||
| var _mock = nock('http://zombo.com') | ||
| .get('/') | ||
| .times(4) | ||
| .reply(200, "Hello World!"); | ||
| for (var i=0; i < 4; i++) { | ||
| http.get('http://zombo.com', function(res) { | ||
| t.equal(200, res.statusCode, 'first request'); | ||
| }); | ||
| }; | ||
| nock.cleanAll() | ||
| t.end(); | ||
| nock.enableNetConnect(); | ||
| }); |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
83776
1.94%2458
2.25%448
2.28%