Update checked-in dependencies
This commit is contained in:
parent
3ba511a8f1
commit
1c4c64199f
175 changed files with 13227 additions and 15136 deletions
160
node_modules/@sinonjs/samsam/lib/create-matcher.js
generated
vendored
160
node_modules/@sinonjs/samsam/lib/create-matcher.js
generated
vendored
|
|
@ -44,20 +44,20 @@ function createMatcher(expectation, message) {
|
|||
|
||||
if (arguments.length > 2) {
|
||||
throw new TypeError(
|
||||
"Expected 1 or 2 arguments, received " + arguments.length
|
||||
`Expected 1 or 2 arguments, received ${arguments.length}`
|
||||
);
|
||||
}
|
||||
|
||||
if (type in TYPE_MAP) {
|
||||
TYPE_MAP[type](m, expectation, message);
|
||||
} else {
|
||||
m.test = function(actual) {
|
||||
m.test = function (actual) {
|
||||
return deepEqual(actual, expectation);
|
||||
};
|
||||
}
|
||||
|
||||
if (!m.message) {
|
||||
m.message = "match(" + valueToString(expectation) + ")";
|
||||
m.message = `match(${valueToString(expectation)})`;
|
||||
}
|
||||
|
||||
return m;
|
||||
|
|
@ -65,48 +65,48 @@ function createMatcher(expectation, message) {
|
|||
|
||||
createMatcher.isMatcher = isMatcher;
|
||||
|
||||
createMatcher.any = createMatcher(function() {
|
||||
createMatcher.any = createMatcher(function () {
|
||||
return true;
|
||||
}, "any");
|
||||
|
||||
createMatcher.defined = createMatcher(function(actual) {
|
||||
createMatcher.defined = createMatcher(function (actual) {
|
||||
return actual !== null && actual !== undefined;
|
||||
}, "defined");
|
||||
|
||||
createMatcher.truthy = createMatcher(function(actual) {
|
||||
createMatcher.truthy = createMatcher(function (actual) {
|
||||
return Boolean(actual);
|
||||
}, "truthy");
|
||||
|
||||
createMatcher.falsy = createMatcher(function(actual) {
|
||||
createMatcher.falsy = createMatcher(function (actual) {
|
||||
return !actual;
|
||||
}, "falsy");
|
||||
|
||||
createMatcher.same = function(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
createMatcher.same = function (expectation) {
|
||||
return createMatcher(function (actual) {
|
||||
return expectation === actual;
|
||||
}, "same(" + valueToString(expectation) + ")");
|
||||
}, `same(${valueToString(expectation)})`);
|
||||
};
|
||||
|
||||
createMatcher.in = function(arrayOfExpectations) {
|
||||
createMatcher.in = function (arrayOfExpectations) {
|
||||
if (typeOf(arrayOfExpectations) !== "array") {
|
||||
throw new TypeError("array expected");
|
||||
}
|
||||
|
||||
return createMatcher(function(actual) {
|
||||
return some(arrayOfExpectations, function(expectation) {
|
||||
return createMatcher(function (actual) {
|
||||
return some(arrayOfExpectations, function (expectation) {
|
||||
return expectation === actual;
|
||||
});
|
||||
}, "in(" + valueToString(arrayOfExpectations) + ")");
|
||||
}, `in(${valueToString(arrayOfExpectations)})`);
|
||||
};
|
||||
|
||||
createMatcher.typeOf = function(type) {
|
||||
createMatcher.typeOf = function (type) {
|
||||
assertType(type, "string", "type");
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
return typeOf(actual) === type;
|
||||
}, 'typeOf("' + type + '")');
|
||||
}, `typeOf("${type}")`);
|
||||
};
|
||||
|
||||
createMatcher.instanceOf = function(type) {
|
||||
createMatcher.instanceOf = function (type) {
|
||||
/* istanbul ignore if */
|
||||
if (
|
||||
typeof Symbol === "undefined" ||
|
||||
|
|
@ -121,9 +121,9 @@ createMatcher.instanceOf = function(type) {
|
|||
"[Symbol.hasInstance]"
|
||||
);
|
||||
}
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
return actual instanceof type;
|
||||
}, "instanceOf(" + (functionName(type) || objectToString(type)) + ")");
|
||||
}, `instanceOf(${functionName(type) || objectToString(type)})`);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -135,15 +135,15 @@ createMatcher.instanceOf = function(type) {
|
|||
* @returns {object} A matcher
|
||||
*/
|
||||
function createPropertyMatcher(propertyTest, messagePrefix) {
|
||||
return function(property, value) {
|
||||
return function (property, value) {
|
||||
assertType(property, "string", "property");
|
||||
var onlyProperty = arguments.length === 1;
|
||||
var message = messagePrefix + '("' + property + '"';
|
||||
var message = `${messagePrefix}("${property}"`;
|
||||
if (!onlyProperty) {
|
||||
message += ", " + valueToString(value);
|
||||
message += `, ${valueToString(value)}`;
|
||||
}
|
||||
message += ")";
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
if (
|
||||
actual === undefined ||
|
||||
actual === null ||
|
||||
|
|
@ -156,26 +156,26 @@ function createPropertyMatcher(propertyTest, messagePrefix) {
|
|||
};
|
||||
}
|
||||
|
||||
createMatcher.has = createPropertyMatcher(function(actual, property) {
|
||||
createMatcher.has = createPropertyMatcher(function (actual, property) {
|
||||
if (typeof actual === "object") {
|
||||
return property in actual;
|
||||
}
|
||||
return actual[property] !== undefined;
|
||||
}, "has");
|
||||
|
||||
createMatcher.hasOwn = createPropertyMatcher(function(actual, property) {
|
||||
createMatcher.hasOwn = createPropertyMatcher(function (actual, property) {
|
||||
return hasOwnProperty(actual, property);
|
||||
}, "hasOwn");
|
||||
|
||||
createMatcher.hasNested = function(property, value) {
|
||||
createMatcher.hasNested = function (property, value) {
|
||||
assertType(property, "string", "property");
|
||||
var onlyProperty = arguments.length === 1;
|
||||
var message = 'hasNested("' + property + '"';
|
||||
var message = `hasNested("${property}"`;
|
||||
if (!onlyProperty) {
|
||||
message += ", " + valueToString(value);
|
||||
message += `, ${valueToString(value)}`;
|
||||
}
|
||||
message += ")";
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
if (
|
||||
actual === undefined ||
|
||||
actual === null ||
|
||||
|
|
@ -187,54 +187,78 @@ createMatcher.hasNested = function(property, value) {
|
|||
}, message);
|
||||
};
|
||||
|
||||
createMatcher.every = function(predicate) {
|
||||
var jsonParseResultTypes = {
|
||||
null: true,
|
||||
boolean: true,
|
||||
number: true,
|
||||
string: true,
|
||||
object: true,
|
||||
array: true,
|
||||
};
|
||||
createMatcher.json = function (value) {
|
||||
if (!jsonParseResultTypes[typeOf(value)]) {
|
||||
throw new TypeError("Value cannot be the result of JSON.parse");
|
||||
}
|
||||
var message = `json(${JSON.stringify(value, null, " ")})`;
|
||||
return createMatcher(function (actual) {
|
||||
var parsed;
|
||||
try {
|
||||
parsed = JSON.parse(actual);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return deepEqual(parsed, value);
|
||||
}, message);
|
||||
};
|
||||
|
||||
createMatcher.every = function (predicate) {
|
||||
assertMatcher(predicate);
|
||||
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
if (typeOf(actual) === "object") {
|
||||
return every(Object.keys(actual), function(key) {
|
||||
return every(Object.keys(actual), function (key) {
|
||||
return predicate.test(actual[key]);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
isIterable(actual) &&
|
||||
every(actual, function(element) {
|
||||
every(actual, function (element) {
|
||||
return predicate.test(element);
|
||||
})
|
||||
);
|
||||
}, "every(" + predicate.message + ")");
|
||||
}, `every(${predicate.message})`);
|
||||
};
|
||||
|
||||
createMatcher.some = function(predicate) {
|
||||
createMatcher.some = function (predicate) {
|
||||
assertMatcher(predicate);
|
||||
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
if (typeOf(actual) === "object") {
|
||||
return !every(Object.keys(actual), function(key) {
|
||||
return !every(Object.keys(actual), function (key) {
|
||||
return !predicate.test(actual[key]);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
isIterable(actual) &&
|
||||
!every(actual, function(element) {
|
||||
!every(actual, function (element) {
|
||||
return !predicate.test(element);
|
||||
})
|
||||
);
|
||||
}, "some(" + predicate.message + ")");
|
||||
}, `some(${predicate.message})`);
|
||||
};
|
||||
|
||||
createMatcher.array = createMatcher.typeOf("array");
|
||||
|
||||
createMatcher.array.deepEquals = function(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
createMatcher.array.deepEquals = function (expectation) {
|
||||
return createMatcher(function (actual) {
|
||||
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
||||
var sameLength = actual.length === expectation.length;
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
sameLength &&
|
||||
every(actual, function(element, index) {
|
||||
every(actual, function (element, index) {
|
||||
var expected = expectation[index];
|
||||
return typeOf(expected) === "array" &&
|
||||
typeOf(element) === "array"
|
||||
|
|
@ -242,97 +266,97 @@ createMatcher.array.deepEquals = function(expectation) {
|
|||
: deepEqual(expected, element);
|
||||
})
|
||||
);
|
||||
}, "deepEquals([" + iterableToString(expectation) + "])");
|
||||
}, `deepEquals([${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.array.startsWith = function(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
createMatcher.array.startsWith = function (expectation) {
|
||||
return createMatcher(function (actual) {
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
every(expectation, function(expectedElement, index) {
|
||||
every(expectation, function (expectedElement, index) {
|
||||
return actual[index] === expectedElement;
|
||||
})
|
||||
);
|
||||
}, "startsWith([" + iterableToString(expectation) + "])");
|
||||
}, `startsWith([${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.array.endsWith = function(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
createMatcher.array.endsWith = function (expectation) {
|
||||
return createMatcher(function (actual) {
|
||||
// This indicates the index in which we should start matching
|
||||
var offset = actual.length - expectation.length;
|
||||
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
every(expectation, function(expectedElement, index) {
|
||||
every(expectation, function (expectedElement, index) {
|
||||
return actual[offset + index] === expectedElement;
|
||||
})
|
||||
);
|
||||
}, "endsWith([" + iterableToString(expectation) + "])");
|
||||
}, `endsWith([${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.array.contains = function(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
createMatcher.array.contains = function (expectation) {
|
||||
return createMatcher(function (actual) {
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
every(expectation, function(expectedElement) {
|
||||
every(expectation, function (expectedElement) {
|
||||
return arrayIndexOf(actual, expectedElement) !== -1;
|
||||
})
|
||||
);
|
||||
}, "contains([" + iterableToString(expectation) + "])");
|
||||
}, `contains([${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.map = createMatcher.typeOf("map");
|
||||
|
||||
createMatcher.map.deepEquals = function mapDeepEquals(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
||||
var sameLength = actual.size === expectation.size;
|
||||
return (
|
||||
typeOf(actual) === "map" &&
|
||||
sameLength &&
|
||||
every(actual, function(element, key) {
|
||||
every(actual, function (element, key) {
|
||||
return expectation.has(key) && expectation.get(key) === element;
|
||||
})
|
||||
);
|
||||
}, "deepEquals(Map[" + iterableToString(expectation) + "])");
|
||||
}, `deepEquals(Map[${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.map.contains = function mapContains(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
return (
|
||||
typeOf(actual) === "map" &&
|
||||
every(expectation, function(element, key) {
|
||||
every(expectation, function (element, key) {
|
||||
return actual.has(key) && actual.get(key) === element;
|
||||
})
|
||||
);
|
||||
}, "contains(Map[" + iterableToString(expectation) + "])");
|
||||
}, `contains(Map[${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.set = createMatcher.typeOf("set");
|
||||
|
||||
createMatcher.set.deepEquals = function setDeepEquals(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
||||
var sameLength = actual.size === expectation.size;
|
||||
return (
|
||||
typeOf(actual) === "set" &&
|
||||
sameLength &&
|
||||
every(actual, function(element) {
|
||||
every(actual, function (element) {
|
||||
return expectation.has(element);
|
||||
})
|
||||
);
|
||||
}, "deepEquals(Set[" + iterableToString(expectation) + "])");
|
||||
}, `deepEquals(Set[${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.set.contains = function setContains(expectation) {
|
||||
return createMatcher(function(actual) {
|
||||
return createMatcher(function (actual) {
|
||||
return (
|
||||
typeOf(actual) === "set" &&
|
||||
every(expectation, function(element) {
|
||||
every(expectation, function (element) {
|
||||
return actual.has(element);
|
||||
})
|
||||
);
|
||||
}, "contains(Set[" + iterableToString(expectation) + "])");
|
||||
}, `contains(Set[${iterableToString(expectation)}])`);
|
||||
};
|
||||
|
||||
createMatcher.bool = createMatcher.typeOf("boolean");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue