parrot-core
Advanced tools
Comparing version 3.1.0 to 4.0.1
@@ -1,28 +0,15 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
Object.defineProperty(exports, "default", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Parrot.default; | ||
} | ||
}); | ||
var _Parrot = require('./Parrot'); | ||
var _Parrot2 = _interopRequireDefault(_Parrot); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = _Parrot2.default; /* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
module.exports = exports['default']; | ||
var _Parrot = _interopRequireDefault(require("./Parrot")); |
@@ -1,143 +0,115 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _utils = require("./utils"); | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Parrot = function Parrot() { | ||
var scenarios = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
(0, _classCallCheck3.default)(this, Parrot); | ||
var _this = this; | ||
_initialiseProps.call(this); | ||
var _scenarios = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
this.scenarios = (0, _utils.normalizeScenarios)(scenarios); | ||
var _Object$keys = (0, _keys2.default)(scenarios); | ||
var _Object$keys2 = (0, _slicedToArray3.default)(_Object$keys, 1); | ||
this.activeScenario = _Object$keys2[0]; | ||
_utils.logger.setScenario(this.activeScenario); | ||
}; /* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this = this; | ||
this.getActiveScenario = function () { | ||
(0, _classCallCheck2.default)(this, Parrot); | ||
(0, _defineProperty2.default)(this, "getActiveScenario", function () { | ||
return _this.activeScenario; | ||
}; | ||
}); | ||
(0, _defineProperty2.default)(this, "setActiveScenario", function (name) { | ||
_this.activeScenario = name; | ||
this.setActiveScenario = function (name) { | ||
_this.activeScenario = name; | ||
_utils.logger.setScenario(name); | ||
}; | ||
this.getScenarios = function () { | ||
return (0, _keys2.default)(_this.scenarios).map(function (name) { | ||
return { name: name, mocks: _this.scenarios[name] }; | ||
}); | ||
(0, _defineProperty2.default)(this, "getScenarios", function () { | ||
return Object.keys(_this.scenarios).map(function (name) { | ||
return { | ||
name: name, | ||
mocks: _this.scenarios[name] | ||
}; | ||
}); | ||
}; | ||
this.setScenarios = function (scenarios) { | ||
}); | ||
(0, _defineProperty2.default)(this, "setScenarios", function (scenarios) { | ||
_this.scenarios = (0, _utils.normalizeScenarios)(scenarios); | ||
}; | ||
this.getScenario = function (name) { | ||
}); | ||
(0, _defineProperty2.default)(this, "getScenario", function (name) { | ||
return _this.scenarios[name]; | ||
}; | ||
}); | ||
(0, _defineProperty2.default)(this, "setScenario", function (name, mocks) { | ||
var scenarios = (0, _defineProperty2.default)({}, name, mocks); | ||
_this.scenarios = _objectSpread({}, _this.scenarios, {}, (0, _utils.normalizeScenarios)(scenarios)); | ||
}); | ||
(0, _defineProperty2.default)(this, "getMock", function (name, index) { | ||
return _this.scenarios[name][index]; | ||
}); | ||
(0, _defineProperty2.default)(this, "setMock", function (name, index, mock) { | ||
_this.scenarios[name][index] = mock; | ||
}); | ||
(0, _defineProperty2.default)(this, "resolve", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee() { | ||
var _len, | ||
platformRequest, | ||
_key, | ||
normalizedRequest, | ||
resolver, | ||
mocks, | ||
mock, | ||
_args = arguments; | ||
this.setScenario = function (name, mocks) { | ||
var scenarios = (0, _defineProperty3.default)({}, name, mocks); | ||
_this.scenarios = (0, _extends3.default)({}, _this.scenarios, (0, _utils.normalizeScenarios)(scenarios)); | ||
}; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
for (_len = _args.length, platformRequest = new Array(_len), _key = 0; _key < _len; _key++) { | ||
platformRequest[_key] = _args[_key]; | ||
} | ||
this.getMock = function (name, index) { | ||
return _this.scenarios[name][index]; | ||
}; | ||
normalizedRequest = _this.normalizeRequest.apply(_this, platformRequest); | ||
resolver = _this.resolver.apply(_this, platformRequest); | ||
mocks = _this.scenarios[_this.activeScenario]; | ||
_context.next = 6; | ||
return (0, _utils.matchMock)(normalizedRequest, platformRequest, mocks); | ||
this.setMock = function (name, index, mock) { | ||
_this.scenarios[name][index] = mock; | ||
}; | ||
case 6: | ||
mock = _context.sent; | ||
return _context.abrupt("return", (0, _utils.resolveResponse)(normalizedRequest, platformRequest, mock, resolver)); | ||
this.resolve = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
for (var _len = arguments.length, platformRequest = Array(_len), _key = 0; _key < _len; _key++) { | ||
platformRequest[_key] = arguments[_key]; | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
this.scenarios = (0, _utils.normalizeScenarios)(_scenarios); | ||
var normalizedRequest, resolver, mocks, mock; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
normalizedRequest = _this.normalizeRequest.apply(_this, platformRequest); | ||
resolver = _this.resolver.apply(_this, platformRequest); | ||
mocks = _this.scenarios[_this.activeScenario]; | ||
_context.next = 5; | ||
return (0, _utils.matchMock)(normalizedRequest, platformRequest, mocks); | ||
var _Object$keys = Object.keys(_scenarios); | ||
case 5: | ||
mock = _context.sent; | ||
return _context.abrupt('return', (0, _utils.resolveResponse)(normalizedRequest, platformRequest, mock, resolver)); | ||
var _Object$keys2 = (0, _slicedToArray2.default)(_Object$keys, 1); | ||
case 7: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
})); | ||
this.activeScenario = _Object$keys2[0]; | ||
return function () { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
_utils.logger.setScenario(this.activeScenario); | ||
}; | ||
exports.default = Parrot; | ||
module.exports = exports['default']; | ||
var _default = Parrot; | ||
exports.default = _default; |
@@ -1,32 +0,25 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = getParams; | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray")); | ||
var _extends3 = require('babel-runtime/helpers/extends'); | ||
var _pathToRegexp = _interopRequireDefault(require("path-to-regexp")); | ||
var _extends4 = _interopRequireDefault(_extends3); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _toArray2 = require('babel-runtime/helpers/toArray'); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var _toArray3 = _interopRequireDefault(_toArray2); | ||
exports.default = getParams; | ||
var _pathToRegexp = require('path-to-regexp'); | ||
var _pathToRegexp2 = _interopRequireDefault(_pathToRegexp); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getParams(path, route) { | ||
var keys = []; | ||
var _pathToRegexp$exec = (0, _pathToRegexp2.default)(route, keys).exec(path), | ||
_pathToRegexp$exec2 = (0, _toArray3.default)(_pathToRegexp$exec), | ||
var _pathToRegexp$exec = (0, _pathToRegexp.default)(route, keys).exec(path), | ||
_pathToRegexp$exec2 = (0, _toArray2.default)(_pathToRegexp$exec), | ||
values = _pathToRegexp$exec2.slice(1); | ||
@@ -36,18 +29,4 @@ | ||
var name = _ref.name; | ||
return (0, _extends4.default)({}, acc, (0, _defineProperty3.default)({}, name, values[index])); | ||
return _objectSpread({}, acc, (0, _defineProperty2.default)({}, name, values[index])); | ||
}, {}); | ||
} /* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
module.exports = exports['default']; | ||
} |
@@ -1,42 +0,39 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.logger = exports.resolveResponse = exports.matchMock = exports.normalizeScenarios = undefined; | ||
Object.defineProperty(exports, "normalizeScenarios", { | ||
enumerable: true, | ||
get: function get() { | ||
return _normalizeScenarios.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "matchMock", { | ||
enumerable: true, | ||
get: function get() { | ||
return _matchMock.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "resolveResponse", { | ||
enumerable: true, | ||
get: function get() { | ||
return _resolveResponse.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "logger", { | ||
enumerable: true, | ||
get: function get() { | ||
return _logger.default; | ||
} | ||
}); | ||
var _normalizeScenarios2 = require('./normalizeScenarios'); | ||
var _normalizeScenarios = _interopRequireDefault(require("./normalizeScenarios")); | ||
var _normalizeScenarios3 = _interopRequireDefault(_normalizeScenarios2); | ||
var _matchMock = _interopRequireDefault(require("./matchMock")); | ||
var _matchMock2 = require('./matchMock'); | ||
var _resolveResponse = _interopRequireDefault(require("./resolveResponse")); | ||
var _matchMock3 = _interopRequireDefault(_matchMock2); | ||
var _resolveResponse2 = require('./resolveResponse'); | ||
var _resolveResponse3 = _interopRequireDefault(_resolveResponse2); | ||
var _logger2 = require('./logger'); | ||
var _logger3 = _interopRequireDefault(_logger2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.normalizeScenarios = _normalizeScenarios3.default; /* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
exports.matchMock = _matchMock3.default; | ||
exports.resolveResponse = _resolveResponse3.default; | ||
exports.logger = _logger3.default; | ||
var _logger = _interopRequireDefault(require("./logger")); |
@@ -1,44 +0,58 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.loggerColors = undefined; | ||
exports.default = exports.loggerColors = void 0; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
/* | ||
* Copyright 2019 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
var _chalk = require('chalk'); | ||
/* eslint no-console: 'off' */ | ||
var loggerColors = { | ||
info: _chalk.default.white, | ||
warn: _chalk.default.yellow, | ||
error: _chalk.default.red | ||
}; | ||
exports.loggerColors = loggerColors; | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var loggerColors = exports.loggerColors = { | ||
info: _chalk2.default.white, | ||
warn: _chalk2.default.yellow, | ||
error: _chalk2.default.red | ||
}; /* eslint no-console: 'off' */ | ||
var infoTemplate = function infoTemplate(message) { | ||
return loggerColors.info('Info: ' + message); | ||
return loggerColors.info("Info: ".concat(message)); | ||
}; | ||
var errorTemplate = function errorTemplate(message) { | ||
return loggerColors.error('Error: ' + message); | ||
return loggerColors.error("Error: ".concat(message)); | ||
}; | ||
var warnTemplate = function warnTemplate(message) { | ||
return loggerColors.warn('Warning: ' + message); | ||
return loggerColors.warn("Warning: ".concat(message)); | ||
}; | ||
var Logger = function () { | ||
var Logger = | ||
/*#__PURE__*/ | ||
function () { | ||
function Logger() { | ||
var output = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : console.log; | ||
(0, _classCallCheck3.default)(this, Logger); | ||
(0, _classCallCheck2.default)(this, Logger); | ||
this.output = output; | ||
@@ -50,4 +64,4 @@ this.info = this.baseTemplate(infoTemplate); | ||
(0, _createClass3.default)(Logger, [{ | ||
key: 'baseTemplate', | ||
(0, _createClass2.default)(Logger, [{ | ||
key: "baseTemplate", | ||
value: function baseTemplate(template) { | ||
@@ -57,7 +71,7 @@ var _this = this; | ||
return function (message, path) { | ||
return _this.output('[Parrot] ' + _chalk2.default.underline(path) + (' ' + _chalk2.default.dim('(' + _this.scenario + ')') + '\n\t' + template(message))); | ||
return _this.output("[Parrot] ".concat(_chalk.default.underline(path)) + " ".concat(_chalk.default.dim("(".concat(_this.scenario, ")")), "\n\t").concat(template(message))); | ||
}; | ||
} | ||
}, { | ||
key: 'setScenario', | ||
key: "setScenario", | ||
value: function setScenario(scenario) { | ||
@@ -71,2 +85,4 @@ this.scenario = scenario; | ||
exports.default = new Logger(); | ||
var _default = new Logger(); | ||
exports.default = _default; |
@@ -1,39 +0,22 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
exports.default = matchMock; | ||
var _util = require('util'); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _util2 = _interopRequireDefault(_util); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _isEqual = require('lodash/isEqual'); | ||
var _util = _interopRequireDefault(require("util")); | ||
var _isEqual2 = _interopRequireDefault(_isEqual); | ||
var _isEqual = _interopRequireDefault(require("lodash/isEqual")); | ||
var _pathToRegexp = require('path-to-regexp'); | ||
var _pathToRegexp = _interopRequireDefault(require("path-to-regexp")); | ||
var _pathToRegexp2 = _interopRequireDefault(_pathToRegexp); | ||
var _logger = _interopRequireDefault(require("./logger")); | ||
var _logger = require('./logger'); | ||
var _logger2 = _interopRequireDefault(_logger); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* | ||
@@ -52,10 +35,11 @@ * Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
*/ | ||
function match(normalizedRequest) { | ||
return function (request) { | ||
return (0, _keys2.default)(request).every(function (property) { | ||
return Object.keys(request).every(function (property) { | ||
if (property === 'path') { | ||
return (0, _pathToRegexp2.default)(request.path).exec(normalizedRequest.path); | ||
} else if (property === 'headers') { | ||
return (0, _keys2.default)(request.headers).every(function (key) { | ||
return (0, _pathToRegexp.default)(request.path).exec(normalizedRequest.path); | ||
} | ||
if (property === 'headers') { | ||
return Object.keys(request.headers).every(function (key) { | ||
return request.headers[key] === normalizedRequest.headers[key]; | ||
@@ -65,3 +49,3 @@ }); | ||
return (0, _isEqual2.default)(normalizedRequest[property], request[property]); | ||
return (0, _isEqual.default)(normalizedRequest[property], request[property]); | ||
}); | ||
@@ -72,21 +56,30 @@ }; | ||
function matchMock(normalizedRequest, platformRequest, mocks) { | ||
var matchedMock = void 0; | ||
var matchedMock; | ||
for (var index = 0; index < mocks.length; index += 1) { | ||
var mock = mocks[index]; | ||
if (typeof mock === 'function') { | ||
var response = mock.apply(undefined, [normalizedRequest, match(normalizedRequest)].concat((0, _toConsumableArray3.default)(platformRequest))); | ||
var response = mock.apply(void 0, [normalizedRequest, match(normalizedRequest)].concat((0, _toConsumableArray2.default)([].concat(platformRequest)))); | ||
if (response) { | ||
matchedMock = { response: response }; | ||
_logger2.default.info('Matched mock function.', normalizedRequest.path); | ||
matchedMock = { | ||
response: response | ||
}; | ||
_logger.default.info('Matched mock function.', normalizedRequest.path); | ||
break; | ||
} | ||
} else if (typeof mock.request === 'function' && mock.request(normalizedRequest, match(normalizedRequest))) { | ||
_logger2.default.info('Matched request function.', normalizedRequest.path); | ||
_logger.default.info('Matched request function.', normalizedRequest.path); | ||
matchedMock = mock; | ||
break; | ||
} else if ((0, _typeof3.default)(mock.request) === 'object' && match(normalizedRequest)(mock.request)) { | ||
_logger2.default.info('Matched request object: ' + _util2.default.inspect(mock.request, { | ||
} else if ((0, _typeof2.default)(mock.request) === 'object' && match(normalizedRequest)(mock.request)) { | ||
_logger.default.info("Matched request object: ".concat(_util.default.inspect(mock.request, { | ||
colors: true, | ||
breakLength: Infinity | ||
}), normalizedRequest.path); | ||
})), normalizedRequest.path); | ||
matchedMock = mock; | ||
@@ -98,3 +91,2 @@ break; | ||
return matchedMock; | ||
} | ||
module.exports = exports['default']; | ||
} |
@@ -1,23 +0,16 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = normalizeScenarios; | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
var _extends4 = require('babel-runtime/helpers/extends'); | ||
var _extends5 = _interopRequireDefault(_extends4); | ||
exports.default = normalizeScenarios; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* | ||
@@ -36,6 +29,5 @@ * Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
*/ | ||
function normalizeMock(mock) { | ||
if (typeof mock !== 'function' && (!mock.request || !mock.response)) { | ||
throw new Error(); | ||
throw new Error('expected mock to be a function'); | ||
} | ||
@@ -49,7 +41,8 @@ | ||
response = mock.response; | ||
var normalizedRequest = typeof request === 'string' ? { | ||
path: request, | ||
method: 'GET' | ||
} : request; | ||
var normalizedResponse = response; | ||
var normalizedRequest = typeof request === 'string' ? { path: request, method: 'GET' } : request; | ||
var normalizedResponse = response; | ||
if (!response.status && !response.body && !response.delay) { | ||
@@ -61,3 +54,3 @@ normalizedResponse = { | ||
} else if (!response.status) { | ||
normalizedResponse = (0, _extends5.default)({ | ||
normalizedResponse = _objectSpread({ | ||
status: 200 | ||
@@ -67,3 +60,6 @@ }, response); | ||
return { request: normalizedRequest, response: normalizedResponse }; | ||
return { | ||
request: normalizedRequest, | ||
response: normalizedResponse | ||
}; | ||
} | ||
@@ -75,15 +71,13 @@ | ||
mocks = _ref.mocks; | ||
return (0, _extends5.default)({}, acc, (0, _defineProperty3.default)({}, name, mocks)); | ||
return _objectSpread({}, acc, (0, _defineProperty2.default)({}, name, mocks)); | ||
}, {}) : scenarios; | ||
return (0, _keys2.default)(normalizedContainer).reduce(function (acc, name) { | ||
return (0, _extends5.default)({}, acc, (0, _defineProperty3.default)({}, name, normalizedContainer[name].map(function (mock, mockIndex) { | ||
return Object.keys(normalizedContainer).reduce(function (acc, name) { | ||
return _objectSpread({}, acc, (0, _defineProperty2.default)({}, name, normalizedContainer[name].map(function (mock, mockIndex) { | ||
try { | ||
return normalizeMock(mock); | ||
} catch (err) { | ||
throw new Error('Mock ' + mockIndex + ' in scenario \'' + name + '\' is not an object with keys request and response or a function.'); | ||
throw new Error("Mock ".concat(mockIndex, " in scenario '").concat(name, "' is not an object with keys request and response or a function.")); | ||
} | ||
}))); | ||
}, {}); | ||
} | ||
module.exports = exports['default']; | ||
} |
@@ -1,38 +0,36 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = resolveResponse; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _getParams = _interopRequireDefault(require("./getParams")); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
// eslint-disable-next-line max-params | ||
function resolveResponse(_x, _x2, _x3, _x4) { | ||
return _resolveResponse.apply(this, arguments); | ||
} | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
function _resolveResponse() { | ||
_resolveResponse = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee(normalizedRequest, platformRequest, mock, resolver) { | ||
var _mock$request, path, response, _ref, body, status, delay, resolvedResponse, requestWithParams; | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _getParams = require('./getParams'); | ||
var _getParams2 = _interopRequireDefault(_getParams); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(normalizedRequest, platformRequest, mock, resolver) { | ||
var _mock$request, path, response, _ref2, body, status, delay, resolvedResponse, requestWithParams; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -46,7 +44,7 @@ switch (_context.prev = _context.next) { | ||
return _context.abrupt('return', resolver()); | ||
return _context.abrupt("return", resolver()); | ||
case 2: | ||
_mock$request = mock.request; | ||
_mock$request = _mock$request === undefined ? {} : _mock$request; | ||
_mock$request = _mock$request === void 0 ? {} : _mock$request; | ||
path = _mock$request.path, response = mock.response; | ||
@@ -57,8 +55,12 @@ _context.next = 7; | ||
case 7: | ||
_ref2 = _context.sent; | ||
body = _ref2.body; | ||
status = _ref2.status; | ||
delay = _ref2.delay; | ||
resolvedResponse = { status: status }; | ||
requestWithParams = path ? (0, _extends3.default)({}, normalizedRequest, { params: (0, _getParams2.default)(normalizedRequest.path, path) }) : normalizedRequest; | ||
_ref = _context.sent; | ||
body = _ref.body; | ||
status = _ref.status; | ||
delay = _ref.delay; | ||
resolvedResponse = { | ||
status: status | ||
}; | ||
requestWithParams = path ? _objectSpread({}, normalizedRequest, { | ||
params: (0, _getParams.default)(normalizedRequest.path, path) | ||
}) : normalizedRequest; | ||
@@ -71,3 +73,3 @@ if (!(typeof body === 'function')) { | ||
_context.next = 16; | ||
return body.apply(undefined, [requestWithParams].concat((0, _toConsumableArray3.default)(platformRequest))); | ||
return body.apply(void 0, [requestWithParams].concat((0, _toConsumableArray2.default)([].concat(platformRequest)))); | ||
@@ -92,3 +94,3 @@ case 16: | ||
return _context.abrupt('return', new _promise2.default(function (resolve) { | ||
return _context.abrupt("return", new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
@@ -100,31 +102,12 @@ return resolve(resolver(resolvedResponse)); | ||
case 24: | ||
return _context.abrupt('return', _promise2.default.resolve(resolver(resolvedResponse))); | ||
return _context.abrupt("return", Promise.resolve(resolver(resolvedResponse))); | ||
case 25: | ||
case 'end': | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee); | ||
})); | ||
function resolveResponse(_x, _x2, _x3, _x4) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return resolveResponse; | ||
}(); /* | ||
* Copyright (c) 2018 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
module.exports = exports['default']; | ||
return _resolveResponse.apply(this, arguments); | ||
} |
{ | ||
"name": "parrot-core", | ||
"version": "3.1.0", | ||
"version": "4.0.1", | ||
"contributors": [ | ||
@@ -23,3 +23,3 @@ "Jack Cross <jack.cross1@aexp.com>", | ||
"dependencies": { | ||
"babel-runtime": "^6.0.0", | ||
"@babel/runtime": "^7.7.7", | ||
"chalk": "^1.1.3", | ||
@@ -31,5 +31,9 @@ "lodash": "^4.16.3", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"rimraf": "^2.2.8" | ||
} | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.7.7", | ||
"@babel/plugin-transform-runtime": "^7.7.6", | ||
"babel-preset-amex": "^3.3.0", | ||
"rimraf": "^3.0.0" | ||
}, | ||
"gitHead": "05e11da9241f5737ada24cfeb613f4f98e2abb89" | ||
} |
@@ -1,4 +0,6 @@ | ||
# parrot-core | ||
<h1 align="center"> | ||
<img src="./parrot-core.png" alt="Parrot-Core" width="50%" /> | ||
</h1> | ||
parrot-core abstracts the matching, logging, and resolving functionality of Parrot away from each implementation. [parrot-middleware](https://github.com/americanexpress/parrot/blob/master/packages/parrot-middleware) and [parrot-fetch](https://github.com/americanexpress/parrot/blob/master/packages/parrot-fetch) use parrot-core and any new implementations could extend parrot-core in a similar way. | ||
parrot-core abstracts the matching, logging, and resolving functionality of Parrot away from each implementation. [parrot-middleware](https://github.com/americanexpress/parrot/blob/master/packages/parrot-middleware) and [parrot-fetch](https://github.com/americanexpress/parrot/blob/master/packages/parrot-fetch) use parrot-core and any new implementations could extend parrot-core in a similar way. | ||
@@ -16,9 +18,9 @@ ## Example Implementation | ||
normalizeRequest = (request) => { | ||
normalizeRequest = request => { | ||
// conform incoming requests to match the scenarios structure | ||
} | ||
}; | ||
resolver = (request) => (response) => { | ||
resolver = request => response => { | ||
// resolve the matched response to the implementation platform | ||
} | ||
}; | ||
} | ||
@@ -43,3 +45,3 @@ | ||
* `name` (_String_): Scenario name. | ||
- `name` (_String_): Scenario name. | ||
@@ -56,3 +58,3 @@ ### `getScenarios()` | ||
* `scenarios` (*Array* or *Object*): Scenarios descriptor. | ||
- `scenarios` (_Array_ or _Object_): Scenarios descriptor. | ||
@@ -65,3 +67,3 @@ ### `getScenario(name)` | ||
* `name` (*String*): Scenario name. | ||
- `name` (_String_): Scenario name. | ||
@@ -74,4 +76,4 @@ ### `setScenario(name, mocks)` | ||
* `name` (*String*): Scenario name. | ||
* `mocks` (*Array*): Array of mock objects. | ||
- `name` (_String_): Scenario name. | ||
- `mocks` (_Array_): Array of mock objects. | ||
@@ -84,4 +86,4 @@ ### `getMock(name, index)` | ||
* `name` (*String*): Scenario name. | ||
* `index` (*Number*): Mock index. | ||
- `name` (_String_): Scenario name. | ||
- `index` (_Number_): Mock index. | ||
@@ -94,5 +96,4 @@ ### `setMock(name, index, mock)` | ||
* `name` (*String*): Scenario name. | ||
* `index` (*Number*): Mock index. | ||
* `mock` (*Object*): Mock object. | ||
- `name` (_String_): Scenario name. | ||
- `index` (_Number_): Mock index. | ||
- `mock` (_Object_): Mock object. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
0
100
93
34243
5
447
2
+ Added@babel/runtime@^7.7.7
+ Added@babel/runtime@7.26.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedbabel-runtime@^6.0.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)