mirror of
https://github.com/chaijs/chai
synced 2024-11-14 15:57:10 +00:00
make
This commit is contained in:
parent
a141e5739a
commit
1a0f887271
1 changed files with 68 additions and 41 deletions
109
chai.js
109
chai.js
|
@ -9251,6 +9251,7 @@ AssertionError.prototype.toJSON = function (stack) {
|
||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var getFunctionName = require('get-func-name');
|
||||||
/**
|
/**
|
||||||
* ### .checkError
|
* ### .checkError
|
||||||
*
|
*
|
||||||
|
@ -9330,34 +9331,6 @@ function compatibleMessage(thrown, errMatcher) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ### .getFunctionName(constructorFn)
|
|
||||||
*
|
|
||||||
* Returns the name of a function.
|
|
||||||
* This also includes a polyfill function if `constructorFn.name` is not defined.
|
|
||||||
*
|
|
||||||
* @name getFunctionName
|
|
||||||
* @param {Function} constructorFn
|
|
||||||
* @namespace Utils
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/;
|
|
||||||
function getFunctionName(constructorFn) {
|
|
||||||
var name = '';
|
|
||||||
if (typeof constructorFn.name === 'undefined') {
|
|
||||||
// Here we run a polyfill if constructorFn.name is not defined
|
|
||||||
var match = String(constructorFn).match(functionNameMatch);
|
|
||||||
if (match) {
|
|
||||||
name = match[1];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
name = constructorFn.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### .getConstructorName(errorLike)
|
* ### .getConstructorName(errorLike)
|
||||||
*
|
*
|
||||||
|
@ -9377,8 +9350,11 @@ function getConstructorName(errorLike) {
|
||||||
// If `err` is not an instance of Error it is an error constructor itself or another function.
|
// If `err` is not an instance of Error it is an error constructor itself or another function.
|
||||||
// If we've got a common function we get its name, otherwise we may need to create a new instance
|
// If we've got a common function we get its name, otherwise we may need to create a new instance
|
||||||
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
|
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
|
||||||
constructorName = getFunctionName(errorLike).trim() ||
|
constructorName = getFunctionName(errorLike);
|
||||||
getFunctionName(new errorLike()); // eslint-disable-line new-cap
|
if (constructorName === '') {
|
||||||
|
var newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
|
||||||
|
constructorName = newConstructorName || constructorName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return constructorName;
|
return constructorName;
|
||||||
|
@ -9416,7 +9392,7 @@ module.exports = {
|
||||||
getConstructorName: getConstructorName,
|
getConstructorName: getConstructorName,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{}],35:[function(require,module,exports){
|
},{"get-func-name":36}],35:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
/* globals Symbol: false, Uint8Array: false, WeakMap: false */
|
/* globals Symbol: false, Uint8Array: false, WeakMap: false */
|
||||||
/*!
|
/*!
|
||||||
|
@ -9811,8 +9787,15 @@ function getEnumerableKeys(target) {
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNonEnumerableSymbols(target) {
|
function getEnumerableSymbols(target) {
|
||||||
var keys = Object.getOwnPropertySymbols(target);
|
var keys = [];
|
||||||
|
var allKeys = Object.getOwnPropertySymbols(target);
|
||||||
|
for (var i = 0; i < allKeys.length; i += 1) {
|
||||||
|
var key = allKeys[i];
|
||||||
|
if (Object.getOwnPropertyDescriptor(target, key).enumerable) {
|
||||||
|
keys.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9851,8 +9834,8 @@ function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
|
||||||
function objectEqual(leftHandOperand, rightHandOperand, options) {
|
function objectEqual(leftHandOperand, rightHandOperand, options) {
|
||||||
var leftHandKeys = getEnumerableKeys(leftHandOperand);
|
var leftHandKeys = getEnumerableKeys(leftHandOperand);
|
||||||
var rightHandKeys = getEnumerableKeys(rightHandOperand);
|
var rightHandKeys = getEnumerableKeys(rightHandOperand);
|
||||||
var leftHandSymbols = getNonEnumerableSymbols(leftHandOperand);
|
var leftHandSymbols = getEnumerableSymbols(leftHandOperand);
|
||||||
var rightHandSymbols = getNonEnumerableSymbols(rightHandOperand);
|
var rightHandSymbols = getEnumerableSymbols(rightHandOperand);
|
||||||
leftHandKeys = leftHandKeys.concat(leftHandSymbols);
|
leftHandKeys = leftHandKeys.concat(leftHandSymbols);
|
||||||
rightHandKeys = rightHandKeys.concat(rightHandSymbols);
|
rightHandKeys = rightHandKeys.concat(rightHandSymbols);
|
||||||
|
|
||||||
|
@ -9928,6 +9911,7 @@ function mapSymbols(arr) {
|
||||||
|
|
||||||
var toString = Function.prototype.toString;
|
var toString = Function.prototype.toString;
|
||||||
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
|
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
|
||||||
|
var maxFunctionSourceLength = 512;
|
||||||
function getFuncName(aFunc) {
|
function getFuncName(aFunc) {
|
||||||
if (typeof aFunc !== 'function') {
|
if (typeof aFunc !== 'function') {
|
||||||
return null;
|
return null;
|
||||||
|
@ -9935,8 +9919,15 @@ function getFuncName(aFunc) {
|
||||||
|
|
||||||
var name = '';
|
var name = '';
|
||||||
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
|
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
|
||||||
|
// eslint-disable-next-line prefer-reflect
|
||||||
|
var functionSource = toString.call(aFunc);
|
||||||
|
// To avoid unconstrained resource consumption due to pathalogically large function names,
|
||||||
|
// we limit the available return value to be less than 512 characters.
|
||||||
|
if (functionSource.indexOf('(') > maxFunctionSourceLength) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
|
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
|
||||||
var match = toString.call(aFunc).match(functionNameMatch);
|
var match = functionSource.match(functionNameMatch);
|
||||||
if (match) {
|
if (match) {
|
||||||
name = match[1];
|
name = match[1];
|
||||||
}
|
}
|
||||||
|
@ -10332,9 +10323,15 @@ module.exports = getFuncName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inspectDate(dateObject, options) {
|
function inspectDate(dateObject, options) {
|
||||||
// If we need to - truncate the time portion, but never the date
|
var stringRepresentation = dateObject.toJSON();
|
||||||
var split = dateObject.toJSON().split('T');
|
|
||||||
var date = split[0];
|
if (stringRepresentation === null) {
|
||||||
|
return 'Invalid Date';
|
||||||
|
}
|
||||||
|
|
||||||
|
var split = stringRepresentation.split('T');
|
||||||
|
var date = split[0]; // If we need to - truncate the time portion, but never the date
|
||||||
|
|
||||||
return options.stylize("".concat(date, "T").concat(truncate(split[1], options.truncate - date.length - 1)), 'date');
|
return options.stylize("".concat(date, "T").concat(truncate(split[1], options.truncate - date.length - 1)), 'date');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10631,7 +10628,32 @@ module.exports = getFuncName;
|
||||||
nodeInspect = false;
|
nodeInspect = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var constructorMap = new WeakMap();
|
function FakeMap() {
|
||||||
|
// eslint-disable-next-line prefer-template
|
||||||
|
this.key = 'chai/loupe__' + Math.random() + Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
FakeMap.prototype = {
|
||||||
|
// eslint-disable-next-line object-shorthand
|
||||||
|
get: function get(key) {
|
||||||
|
return key[this.key];
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line object-shorthand
|
||||||
|
has: function has(key) {
|
||||||
|
return this.key in key;
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line object-shorthand
|
||||||
|
set: function set(key, value) {
|
||||||
|
if (Object.isExtensible(key)) {
|
||||||
|
Object.defineProperty(key, this.key, {
|
||||||
|
// eslint-disable-next-line object-shorthand
|
||||||
|
value: value,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)();
|
||||||
var stringTagMap = {};
|
var stringTagMap = {};
|
||||||
var baseTypesMap = {
|
var baseTypesMap = {
|
||||||
undefined: function undefined$1(value, options) {
|
undefined: function undefined$1(value, options) {
|
||||||
|
@ -10765,6 +10787,11 @@ module.exports = getFuncName;
|
||||||
} // If it is an object with an anonymous prototype, display it as an object.
|
} // If it is an object with an anonymous prototype, display it as an object.
|
||||||
|
|
||||||
|
|
||||||
|
return inspectObject(value, options);
|
||||||
|
} // last chance to check if it's an object
|
||||||
|
|
||||||
|
|
||||||
|
if (value === Object(value)) {
|
||||||
return inspectObject(value, options);
|
return inspectObject(value, options);
|
||||||
} // We have run out of options! Just stringify the value
|
} // We have run out of options! Just stringify the value
|
||||||
|
|
||||||
|
@ -10776,7 +10803,7 @@ module.exports = getFuncName;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructorMap.add(constructor, inspector);
|
constructorMap.set(constructor, inspector);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function registerStringTag(stringTag, inspector) {
|
function registerStringTag(stringTag, inspector) {
|
||||||
|
|
Loading…
Reference in a new issue