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:
22
src/core/deprecateMonkeyPatching.js
Normal file
22
src/core/deprecateMonkeyPatching.js
Normal file
@@ -0,0 +1,22 @@
|
||||
getJasmineRequireObj().deprecateMonkeyPatching = function(j$) {
|
||||
return function deprecateMonkeyPatching(obj, keysToSkip) {
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (!keysToSkip?.includes(key)) {
|
||||
let value = obj[key];
|
||||
|
||||
Object.defineProperty(obj, key, {
|
||||
enumerable: key in obj,
|
||||
get() {
|
||||
return value;
|
||||
},
|
||||
set(newValue) {
|
||||
j$.getEnv().deprecated(
|
||||
'Monkey patching detected. This is not supported and will break in a future jasmine-core release.'
|
||||
);
|
||||
value = newValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user