fetch-mock
Advanced tools
Comparing version 9.10.6 to 9.10.7
@@ -5,14 +5,10 @@ const { debug } = require('./debug'); | ||
const inspecting = require('./inspecting'); | ||
const matchers = require('./matchers'); | ||
const compileRoute = require('./compile-route'); | ||
const Route = require('../Route'); | ||
const FetchMock = Object.assign( | ||
{}, | ||
fetchHandler, | ||
setUpAndTearDown, | ||
inspecting, | ||
compileRoute, | ||
matchers | ||
); | ||
const FetchMock = Object.assign({}, fetchHandler, setUpAndTearDown, inspecting); | ||
FetchMock.addMatcher = function (matcher) { | ||
Route.addMatcher(matcher); | ||
}; | ||
FetchMock.config = { | ||
@@ -30,5 +26,4 @@ fallbackToNetwork: false, | ||
instance._uncompiledRoutes = (this._uncompiledRoutes || []).slice(); | ||
instance._matchers = this._matchers.slice(); | ||
instance.routes = instance._uncompiledRoutes.map((config) => | ||
instance.compileRoute(config) | ||
this.compileRoute(config) | ||
); | ||
@@ -43,2 +38,6 @@ instance.fallbackResponse = this.fallbackResponse || undefined; | ||
FetchMock.compileRoute = function (config) { | ||
return new Route(config, this); | ||
}; | ||
FetchMock.bindMethods = function () { | ||
@@ -45,0 +44,0 @@ this.fetchHandler = FetchMock.fetchHandler.bind(this); |
const { setDebugPhase, setDebugNamespace, debug } = require('./debug'); | ||
const { normalizeUrl } = require('./request-utils'); | ||
const Route = require('../Route'); | ||
const FetchMock = {}; | ||
@@ -8,5 +9,6 @@ const isName = (nameOrMatcher) => | ||
const filterCallsWithMatcher = function (matcher, options = {}, calls) { | ||
matcher = this.generateMatcher( | ||
this.sanitizeRoute(Object.assign({ matcher }, options)) | ||
); | ||
({ matcher } = new Route( | ||
[Object.assign({ matcher, response: 'ok' }, options)], | ||
this | ||
)); | ||
return calls.filter(({ url, options }) => | ||
@@ -13,0 +15,0 @@ matcher(normalizeUrl(url), options) |
@@ -19,7 +19,10 @@ 'use strict'; | ||
var inspecting = require('./inspecting'); | ||
var matchers = require('./matchers'); | ||
var compileRoute = require('./compile-route'); | ||
var Route = require('../Route'); | ||
var FetchMock = (0, _assign2.default)({}, fetchHandler, setUpAndTearDown, inspecting, compileRoute, matchers); | ||
var FetchMock = (0, _assign2.default)({}, fetchHandler, setUpAndTearDown, inspecting); | ||
FetchMock.addMatcher = function (matcher) { | ||
Route.addMatcher(matcher); | ||
}; | ||
FetchMock.config = { | ||
@@ -34,8 +37,9 @@ fallbackToNetwork: false, | ||
FetchMock.createInstance = function () { | ||
var _this = this; | ||
debug('Creating fetch-mock instance'); | ||
var instance = (0, _create2.default)(FetchMock); | ||
instance._uncompiledRoutes = (this._uncompiledRoutes || []).slice(); | ||
instance._matchers = this._matchers.slice(); | ||
instance.routes = instance._uncompiledRoutes.map(function (config) { | ||
return instance.compileRoute(config); | ||
return _this.compileRoute(config); | ||
}); | ||
@@ -50,2 +54,6 @@ instance.fallbackResponse = this.fallbackResponse || undefined; | ||
FetchMock.compileRoute = function (config) { | ||
return new Route(config, this); | ||
}; | ||
FetchMock.bindMethods = function () { | ||
@@ -52,0 +60,0 @@ this.fetchHandler = FetchMock.fetchHandler.bind(this); |
@@ -41,2 +41,3 @@ 'use strict'; | ||
var Route = require('../Route'); | ||
var FetchMock = {}; | ||
@@ -51,6 +52,9 @@ var isName = function isName(nameOrMatcher) { | ||
matcher = this.generateMatcher(this.sanitizeRoute((0, _assign2.default)({ matcher: matcher }, options))); | ||
return calls.filter(function (_ref) { | ||
var url = _ref.url, | ||
options = _ref.options; | ||
var _ref = new Route([(0, _assign2.default)({ matcher: matcher, response: 'ok' }, options)], this); | ||
matcher = _ref.matcher; | ||
return calls.filter(function (_ref2) { | ||
var url = _ref2.url, | ||
options = _ref2.options; | ||
return matcher(normalizeUrl(url), options); | ||
@@ -100,4 +104,4 @@ }); | ||
debug('Filter provided is ' + nameOrMatcher + '. Returning matched calls only'); | ||
calls = calls.filter(function (_ref2) { | ||
var isUnmatched = _ref2.isUnmatched; | ||
calls = calls.filter(function (_ref3) { | ||
var isUnmatched = _ref3.isUnmatched; | ||
return !isUnmatched; | ||
@@ -107,4 +111,4 @@ }); | ||
debug('Filter provided is ' + nameOrMatcher + '. Returning unmatched calls only'); | ||
calls = calls.filter(function (_ref3) { | ||
var isUnmatched = _ref3.isUnmatched; | ||
calls = calls.filter(function (_ref4) { | ||
var isUnmatched = _ref4.isUnmatched; | ||
return isUnmatched; | ||
@@ -117,4 +121,4 @@ }); | ||
debug('Filter provided, looks like the name of a named route. Returning only calls handled by that route'); | ||
calls = calls.filter(function (_ref4) { | ||
var identifier = _ref4.identifier; | ||
calls = calls.filter(function (_ref5) { | ||
var identifier = _ref5.identifier; | ||
return identifier === nameOrMatcher; | ||
@@ -124,4 +128,4 @@ }); | ||
matcher = nameOrMatcher === '*' ? '*' : normalizeUrl(nameOrMatcher); | ||
if (this.routes.some(function (_ref5) { | ||
var identifier = _ref5.identifier; | ||
if (this.routes.some(function (_ref6) { | ||
var identifier = _ref6.identifier; | ||
return identifier === matcher; | ||
@@ -175,6 +179,6 @@ })) { | ||
} catch (err) { | ||
(0, _entries2.default)(response._fmResults).forEach(function (_ref6) { | ||
var _ref7 = (0, _slicedToArray3.default)(_ref6, 2), | ||
name = _ref7[0], | ||
result = _ref7[1]; | ||
(0, _entries2.default)(response._fmResults).forEach(function (_ref7) { | ||
var _ref8 = (0, _slicedToArray3.default)(_ref7, 2), | ||
name = _ref8[0], | ||
result = _ref8[1]; | ||
@@ -195,3 +199,3 @@ response[name] = function () { | ||
FetchMock.flush = formatDebug(function () { | ||
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(waitForResponseMethods) { | ||
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(waitForResponseMethods) { | ||
var queuedPromises; | ||
@@ -240,3 +244,3 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
return function (_x2) { | ||
return _ref8.apply(this, arguments); | ||
return _ref9.apply(this, arguments); | ||
}; | ||
@@ -263,4 +267,4 @@ }()); | ||
// break the logging | ||
var result = routesToCheck.map(function (_ref9) { | ||
var identifier = _ref9.identifier; | ||
var result = routesToCheck.map(function (_ref10) { | ||
var identifier = _ref10.identifier; | ||
@@ -267,0 +271,0 @@ if (!_this.called(identifier)) { |
{ | ||
"name": "fetch-mock", | ||
"version": "9.10.6", | ||
"version": "9.10.7", | ||
"description": "Mock http requests made using fetch (or isomorphic-fetch)", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/server.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
2898515
83049