Removed deprecated custom matcher, matchersUtil, pp, etc interfaces

This commit is contained in:
Steve Gravrock
2020-02-12 15:38:52 -08:00
committed by Steve Gravrock
parent 66189d742b
commit 4b2a14f1f3
11 changed files with 33 additions and 1169 deletions

View File

@@ -302,17 +302,6 @@ getJasmineRequireObj().Env = function(j$) {
runnableResources[currentRunnable().id].customMatchers;
for (var matcherName in matchersToAdd) {
if (matchersToAdd[matcherName].length > 1) {
self.deprecatedOnceWithStack(
'The matcher factory for "' +
matcherName +
'" ' +
'accepts custom equality testers, but this parameter will no longer be ' +
'passed in a future release. ' +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
}
customMatchers[matcherName] = matchersToAdd[matcherName];
}
};
@@ -327,17 +316,6 @@ getJasmineRequireObj().Env = function(j$) {
runnableResources[currentRunnable().id].customAsyncMatchers;
for (var matcherName in matchersToAdd) {
if (matchersToAdd[matcherName].length > 1) {
self.deprecatedOnceWithStack(
'The matcher factory for "' +
matcherName +
'" ' +
'accepts custom equality testers, but this parameter will no longer be ' +
'passed in a future release. ' +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
}
customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
}
};
@@ -383,12 +361,8 @@ getJasmineRequireObj().Env = function(j$) {
};
var expectationFactory = function(actual, spec) {
var customEqualityTesters =
runnableResources[spec.id].customEqualityTesters;
return j$.Expectation.factory({
matchersUtil: makeMatchersUtil(),
customEqualityTesters: customEqualityTesters,
customMatchers: runnableResources[spec.id].customMatchers,
actual: actual,
addExpectationResult: addExpectationResult
@@ -428,7 +402,6 @@ getJasmineRequireObj().Env = function(j$) {
var asyncExpectationFactory = function(actual, spec, runableType) {
return j$.Expectation.asyncFactory({
matchersUtil: makeMatchersUtil(),
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
actual: actual,
addExpectationResult: addExpectationResult

View File

@@ -3,7 +3,6 @@ getJasmineRequireObj().Expector = function(j$) {
this.matchersUtil = options.matchersUtil || {
buildFailureMessage: function() {}
};
this.customEqualityTesters = options.customEqualityTesters || [];
this.actual = options.actual;
this.addExpectationResult = options.addExpectationResult || function() {};
this.filters = new j$.ExpectationFilterChain();
@@ -20,14 +19,7 @@ getJasmineRequireObj().Expector = function(j$) {
this.args.unshift(this.actual);
// TODO: Remove support for passing customEqualityTesters in the next major release.
var matcher;
if (matcherFactory.length >= 2) {
matcher = matcherFactory(this.matchersUtil, this.customEqualityTesters);
} else {
matcher = matcherFactory(this.matchersUtil);
}
var matcher = matcherFactory(this.matchersUtil);
var comparisonFunc = this.filters.selectComparisonFunc(matcher);
return comparisonFunc || matcher.compare;

View File

@@ -1,122 +0,0 @@
getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
/*
Older versions of Jasmine passed an array of custom equality testers as the
second argument to each asymmetric equality tester's `asymmetricMatch`
method. Newer versions will pass a `MatchersUtil` instance. The
asymmetricEqualityTesterArgCompatShim allows for a graceful migration from
the old interface to the new by "being" both an array of custom equality
testers and a `MatchersUtil` at the same time.
This code should be removed in the next major release.
*/
var likelyArrayProps = [
'concat',
'constructor',
'copyWithin',
'entries',
'every',
'fill',
'filter',
'find',
'findIndex',
'flat',
'flatMap',
'forEach',
'includes',
'indexOf',
'join',
'keys',
'lastIndexOf',
'length',
'map',
'pop',
'push',
'reduce',
'reduceRight',
'reverse',
'shift',
'slice',
'some',
'sort',
'splice',
'toLocaleString',
'toSource',
'toString',
'unshift',
'values'
];
function asymmetricEqualityTesterArgCompatShim(
matchersUtil,
customEqualityTesters
) {
var self = Object.create(matchersUtil);
copyAndDeprecate(self, customEqualityTesters, 'length');
for (i = 0; i < customEqualityTesters.length; i++) {
copyAndDeprecate(self, customEqualityTesters, i);
}
// Avoid copying array props if we've previously done so,
// to avoid triggering our own deprecation warnings.
if (!self.isAsymmetricEqualityTesterArgCompatShim_) {
copyAndDeprecateArrayMethods(self);
}
self.isAsymmetricEqualityTesterArgCompatShim_ = true;
return self;
}
function copyAndDeprecateArrayMethods(dest) {
var props = arrayProps(),
i,
k;
for (i = 0; i < props.length; i++) {
k = props[i];
// Skip length (dealt with above), and anything that collides with
// MatchesUtil e.g. an Array.prototype.contains method added by user code
if (k !== 'length' && !dest[k]) {
copyAndDeprecate(dest, Array.prototype, k);
}
}
}
function copyAndDeprecate(dest, src, propName) {
Object.defineProperty(dest, propName, {
get: function() {
j$.getEnv().deprecated(
'The second argument to asymmetricMatch is now a ' +
'MatchersUtil. Using it as an array of custom equality testers is ' +
'deprecated and will stop working in a future release. ' +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return src[propName];
}
});
}
function arrayProps() {
var props, a, k;
if (!Object.getOwnPropertyDescriptors) {
return likelyArrayProps.filter(function(k) {
return Array.prototype.hasOwnProperty(k);
});
}
props = Object.getOwnPropertyDescriptors(Array.prototype); // eslint-disable-line compat/compat
a = [];
for (k in props) {
a.push(k);
}
return a;
}
return asymmetricEqualityTesterArgCompatShim;
};

View File

@@ -29,19 +29,9 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
* @since 2.0.0
* @param {*} haystack The collection to search
* @param {*} needle The value to search for
* @param [customTesters] An array of custom equality testers. Deprecated.
* As of 3.6 this parameter no longer needs to be passed. It will be removed in 4.0.
* @returns {boolean} True if `needle` was found in `haystack`
*/
MatchersUtil.prototype.contains = function(haystack, needle, customTesters) {
if (customTesters) {
j$.getEnv().deprecatedOnceWithStack(
'Passing custom equality testers ' +
'to MatchersUtil#contains is deprecated. ' +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
}
MatchersUtil.prototype.contains = function(haystack, needle) {
if (j$.isSet(haystack)) {
return haystack.has(needle);
}
@@ -51,7 +41,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
(!!haystack && !haystack.indexOf)
) {
for (var i = 0; i < haystack.length; i++) {
if (this.equals(haystack[i], needle, customTesters)) {
if (this.equals(haystack[i], needle)) {
return true;
}
}
@@ -95,19 +85,11 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
b,
aStack,
bStack,
customTesters,
diffBuilder
) {
if (j$.isFunction_(b.valuesForDiff_)) {
var values = b.valuesForDiff_(a, this.pp);
this.eq_(
values.other,
values.self,
aStack,
bStack,
customTesters,
diffBuilder
);
this.eq_(values.other, values.self, aStack, bStack, diffBuilder);
} else {
diffBuilder.recordMismatch();
}
@@ -118,22 +100,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
b,
aStack,
bStack,
customTesters,
diffBuilder
) {
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
asymmetricB = j$.isAsymmetricEqualityTester_(b),
shim,
result;
if (asymmetricA === asymmetricB) {
return undefined;
}
shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters);
if (asymmetricA) {
result = a.asymmetricMatch(b, shim);
result = a.asymmetricMatch(b, this);
if (!result) {
diffBuilder.recordMismatch();
}
@@ -141,9 +119,9 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
}
if (asymmetricB) {
result = b.asymmetricMatch(a, shim);
result = b.asymmetricMatch(a, this);
if (!result) {
this.asymmetricDiff_(a, b, aStack, bStack, customTesters, diffBuilder);
this.asymmetricDiff_(a, b, aStack, bStack, diffBuilder);
}
return result;
}
@@ -156,58 +134,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
* @since 2.0.0
* @param {*} a The first value to compare
* @param {*} b The second value to compare
* @param [customTesters] An array of custom equality testers. Deprecated.
* As of 3.6 this parameter no longer needs to be passed. It will be removed in 4.0.
* @returns {boolean} True if the values are equal
*/
MatchersUtil.prototype.equals = function(
a,
b,
customTestersOrDiffBuilder,
diffBuilderOrNothing
) {
var customTesters, diffBuilder;
if (isDiffBuilder(customTestersOrDiffBuilder)) {
diffBuilder = customTestersOrDiffBuilder;
} else {
if (customTestersOrDiffBuilder) {
j$.getEnv().deprecatedOnceWithStack(
'Passing custom equality testers ' +
'to MatchersUtil#equals is deprecated. ' +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
}
if (diffBuilderOrNothing) {
j$.getEnv().deprecatedOnceWithStack(
'Diff builder should be passed ' +
'as the third argument to MatchersUtil#equals, not the fourth. ' +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
}
customTesters = customTestersOrDiffBuilder;
diffBuilder = diffBuilderOrNothing;
}
customTesters = customTesters || this.customTesters_;
MatchersUtil.prototype.equals = function(a, b, diffBuilder) {
diffBuilder = diffBuilder || j$.NullDiffBuilder();
diffBuilder.setRoots(a, b);
return this.eq_(a, b, [], [], customTesters, diffBuilder);
return this.eq_(a, b, [], [], diffBuilder);
};
// Equality function lovingly adapted from isEqual in
// [Underscore](http://underscorejs.org)
MatchersUtil.prototype.eq_ = function(
a,
b,
aStack,
bStack,
customTesters,
diffBuilder
) {
MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) {
var result = true,
self = this,
i;
@@ -217,15 +155,14 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
b,
aStack,
bStack,
customTesters,
diffBuilder
);
if (!j$.util.isUndefined(asymmetricResult)) {
return asymmetricResult;
}
for (i = 0; i < customTesters.length; i++) {
var customTesterResult = customTesters[i](a, b);
for (i = 0; i < this.customTesters_.length; i++) {
var customTesterResult = this.customTesters_[i](a, b);
if (!j$.util.isUndefined(customTesterResult)) {
if (!customTesterResult) {
diffBuilder.recordMismatch();
@@ -301,7 +238,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
new Uint8Array(b), // eslint-disable-line compat/compat
aStack,
bStack,
customTesters,
diffBuilder
);
// RegExps are compared by their source patterns and flags.
@@ -380,7 +316,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
i < bLength ? b[i] : void 0,
aStack,
bStack,
customTesters,
diffBuilder
) && result;
}
@@ -425,14 +360,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
if (
j$.isAsymmetricEqualityTester_(mapKey) ||
(j$.isAsymmetricEqualityTester_(cmpKey) &&
this.eq_(
mapKey,
cmpKey,
aStack,
bStack,
customTesters,
j$.NullDiffBuilder()
))
this.eq_(mapKey, cmpKey, aStack, bStack, j$.NullDiffBuilder()))
) {
mapValueB = b.get(cmpKey);
} else {
@@ -443,7 +371,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
mapValueB,
aStack,
bStack,
customTesters,
j$.NullDiffBuilder()
);
}
@@ -494,7 +421,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
otherValue,
baseStack,
otherStack,
customTesters,
j$.NullDiffBuilder()
);
if (!found && prevStackSize !== baseStack.length) {
@@ -559,9 +485,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
}
diffBuilder.withPath(key, function() {
if (
!self.eq_(a[key], b[key], aStack, bStack, customTesters, diffBuilder)
) {
if (!self.eq_(a[key], b[key], aStack, bStack, diffBuilder)) {
result = false;
}
});
@@ -673,9 +597,5 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
return formatted;
}
function isDiffBuilder(obj) {
return obj && typeof obj.recordMismatch === 'function';
}
return MatchersUtil;
};

View File

@@ -50,40 +50,9 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
j$.Expectation = jRequire.Expectation(j$);
j$.buildExpectationResult = jRequire.buildExpectationResult(j$);
j$.JsApiReporter = jRequire.JsApiReporter(j$);
j$.asymmetricEqualityTesterArgCompatShim = jRequire.asymmetricEqualityTesterArgCompatShim(
j$
);
j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$);
j$.basicPrettyPrinter_ = j$.makePrettyPrinter();
Object.defineProperty(j$, 'pp', {
get: function() {
j$.getEnv().deprecatedOnceWithStack(
'jasmine.pp is deprecated and will be removed in a future release. ' +
'Use the pp method of the matchersUtil passed to the matcher factory ' +
"or the asymmetric equality tester's `asymmetricMatch` method " +
'instead. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return j$.basicPrettyPrinter_;
}
});
j$.MatchersUtil = jRequire.MatchersUtil(j$);
var staticMatchersUtil = new j$.MatchersUtil({
customTesters: [],
pp: j$.basicPrettyPrinter_
});
Object.defineProperty(j$, 'matchersUtil', {
get: function() {
j$.getEnv().deprecatedOnceWithStack(
'jasmine.matchersUtil is deprecated and will be removed ' +
'in a future release. Use the instance passed to the matcher factory or ' +
"the asymmetric equality tester's `asymmetricMatch` method instead. " +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return staticMatchersUtil;
}
});
j$.ObjectContaining = jRequire.ObjectContaining(j$);
j$.ArrayContaining = jRequire.ArrayContaining(j$);
j$.ArrayWithExactContents = jRequire.ArrayWithExactContents(j$);