Comparing version 2.1.0 to 2.2.0
@@ -177,6 +177,9 @@ var fetchImpl = require('./adapter/fetch-node') | ||
// Log each call that was made so tests can verify | ||
var allCalled = [] | ||
function fetchVCR(url, args) { | ||
// Try to load the response from the fixture. | ||
// Then, if a fixture was not found, either fetch it for reals or error (depending on the VCR_MODE) | ||
return new Promise(function (resolve, reject) { | ||
const promise = new Promise(function (resolve, reject) { | ||
if (CONFIGURATION.mode === 'record') { | ||
@@ -211,2 +214,18 @@ // Perform the fetch, save the response, and then yield the original response | ||
}) | ||
return promise.then(function (resp) { | ||
// Record that the request succeeded | ||
var hash = buildHash(url, args) | ||
var bodyFilename = buildBodyFilename(url, args, hash) | ||
var optionsFilename = buildOptionsFilename(url, args, hash) | ||
allCalled.push({ | ||
url: url, | ||
args: args, | ||
response: resp, | ||
hash: hash, | ||
bodyFilename: bodyFilename, | ||
optionsFilename: optionsFilename | ||
}) | ||
return resp | ||
}) | ||
} | ||
@@ -225,5 +244,15 @@ | ||
function getCalled() { | ||
return allCalled | ||
} | ||
function clearCalled() { | ||
allCalled = [] | ||
} | ||
fetchVCR.loadFile = loadFile | ||
fetchVCR.saveFile = saveFile | ||
fetchVCR.getCalled = getCalled | ||
fetchVCR.clearCalled = clearCalled | ||
module.exports = fetchVCR |
{ | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"name": "fetch-vcr", | ||
@@ -4,0 +4,0 @@ "description": "Stop mocking HTTP Requests. Just record and then play them back", |
@@ -78,2 +78,12 @@ # fetch-vcr | ||
If you want to check which calls were made, you can use the following: | ||
```js | ||
// Returns an array of {url, args, hash, bodyFilename, response, optionsFilename} | ||
const allCalls = fetchVCR.getCalled() | ||
// Clears the array of calls made | ||
fetchVCR.clearCalled() | ||
``` | ||
## jsdom Setup | ||
@@ -80,0 +90,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105468
391
140