Detect monkey patching and emit a deprecation warning.
This isn't comprehensive but it should be broad enough to ensure that most people who would be affected by blocking monkey patching see a warning. Covers the jasmine namespace as well as classes that are monkey patched by zone.js. Replacing globals (describe/it/etc) doesn't trigger a warning because they belong to the user and are expected to be replaced.
This commit is contained in:
@@ -296,10 +296,13 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
* @param {String|Error} deprecation The deprecation message
|
||||
* @param {Object} [options] Optional extra options, as described above
|
||||
*/
|
||||
this.deprecated = function(deprecation, options) {
|
||||
const runable = runner.currentRunable() || topSuite;
|
||||
deprecator.addDeprecationWarning(runable, deprecation, options);
|
||||
};
|
||||
Object.defineProperty(this, 'deprecated', {
|
||||
enumerable: true,
|
||||
value: function(deprecation, options) {
|
||||
const runable = runner.currentRunable() || topSuite;
|
||||
deprecator.addDeprecationWarning(runable, deprecation, options);
|
||||
}
|
||||
});
|
||||
|
||||
function runQueue(options) {
|
||||
options.clearStack = options.clearStack || stackClearer;
|
||||
@@ -326,7 +329,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
runQueue
|
||||
});
|
||||
topSuite = suiteBuilder.topSuite;
|
||||
const deprecator = new j$.private.Deprecator(topSuite);
|
||||
const deprecator =
|
||||
envOptions?.deprecator ?? new j$.private.Deprecator(topSuite);
|
||||
|
||||
/**
|
||||
* Provides the root suite, through which all suites and specs can be
|
||||
@@ -831,6 +835,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
this.cleanup_ = function() {
|
||||
uninstallGlobalErrors();
|
||||
};
|
||||
|
||||
j$.private.deprecateMonkeyPatching(this, ['deprecated']);
|
||||
}
|
||||
|
||||
function indirectCallerFilename(depth) {
|
||||
|
||||
Reference in New Issue
Block a user