From 876de65803efd3d1f557d76ad209242ee61a4604 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 27 Nov 2025 09:38:54 -0800 Subject: [PATCH] rm monkey patch warnings --- lib/jasmine-core/jasmine.js | 45 ---------------- spec/core/ClockSpec.js | 21 -------- spec/core/EnvSpec.js | 40 --------------- spec/core/jasmineNamespaceSpec.js | 80 +---------------------------- src/core/Clock.js | 2 - src/core/Env.js | 2 - src/core/deprecateMonkeyPatching.js | 22 -------- src/core/requireCore.js | 15 ------ src/core/requireInterface.js | 3 -- 9 files changed, 2 insertions(+), 228 deletions(-) delete mode 100644 src/core/deprecateMonkeyPatching.js diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 08d7c19f..ced0b20d 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -51,7 +51,6 @@ var getJasmineRequireObj = (function() { }); jRequire.base(j$, globalThis); - j$.private.deprecateMonkeyPatching = jRequire.deprecateMonkeyPatching(j$); j$.private.util = jRequire.util(j$); j$.private.errors = jRequire.errors(); j$.private.formatErrorMsg = jRequire.formatErrorMsg(j$); @@ -127,20 +126,6 @@ var getJasmineRequireObj = (function() { j$.private.loadedAsBrowserEsm = globalThis.document && !globalThis.document.currentScript; - j$.private.deprecateMonkeyPatching(j$, [ - // These are meant to be set by users. - 'DEFAULT_TIMEOUT_INTERVAL', - 'MAX_PRETTY_PRINT_ARRAY_LENGTH', - 'MAX_PRETTY_PRINT_CHARS', - 'MAX_PRETTY_PRINT_DEPTH', - - // These are part of the deprecation warning mechanism. To avoid infinite - // recursion, they're separately protected in a way that doesn't emit - // deprecation warnings. - 'private', - 'getEnv' - ]); - return j$; }; @@ -2077,8 +2062,6 @@ getJasmineRequireObj().Env = function(j$) { this.cleanup_ = function() { uninstallGlobalErrors(); }; - - j$.private.deprecateMonkeyPatching(this, ['deprecated']); } function indirectCallerFilename(depth) { @@ -3147,8 +3130,6 @@ callbacks to execute _before_ running the next one. setInterval[IsMockClockTimingFn] = true; clearInterval[IsMockClockTimingFn] = true; - j$.private.deprecateMonkeyPatching(this); - return this; // Advances the Clock's time until the mode changes. @@ -3857,29 +3838,6 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { return DelayedFunctionScheduler; }; -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; - } - }); - } - } - }; -}; - getJasmineRequireObj().Deprecator = function(j$) { 'use strict'; @@ -9424,7 +9382,6 @@ getJasmineRequireObj().interface = function(jasmine, env) { */ jasmine: jasmine }; - const existingKeys = Object.keys(jasmine); /** * Add a custom equality tester for the current scope of specs. @@ -9591,8 +9548,6 @@ getJasmineRequireObj().interface = function(jasmine, env) { * @namespace asymmetricEqualityTesters */ - jasmine.private.deprecateMonkeyPatching(jasmine, existingKeys); - return jasmineInterface; }; diff --git a/spec/core/ClockSpec.js b/spec/core/ClockSpec.js index 719fbca1..a4d92f85 100644 --- a/spec/core/ClockSpec.js +++ b/spec/core/ClockSpec.js @@ -1247,25 +1247,4 @@ describe('Clock (acceptance)', function() { clock.tick(400); }); - - describe('Warning about monkey patching', function() { - for (const name of ['tick', 'mockDate', 'install', 'uninstall']) { - it(`warns if Clock#${name} is monkey patched`, function() { - spyOn(console, 'error'); - const clock = new privateUnderTest.Clock({}, function() {}, {}); - const patch = {}; - clock[name] = patch; - - // eslint-disable-next-line no-console - expect(console.error).toHaveBeenCalledOnceWith( - jasmine.stringContaining('DEPRECATION: Monkey patching detected.') - ); - // eslint-disable-next-line no-console - expect(console.error).toHaveBeenCalledOnceWith( - jasmine.stringContaining('ClockSpec.js') - ); - expect(clock[name]).toBe(patch); - }); - } - }); }); diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index 8142bf4e..3da94a51 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -874,44 +874,4 @@ describe('Env', function() { }).toThrowError('Jasmine cannot be configured via Env in parallel mode'); }); }); - - describe('Warning about monkey patching', function() { - afterEach(function() { - // deprecateMonkeyPatching() uses jasmine.getEnv(), not the env from - // this suite. Clean it up so we don't leak event listeners. - jasmineUnderTest.getEnv().cleanup_(); - privateUnderTest.currentEnv_ = null; - }); - - const names = [ - 'describe', - 'xdescribe', - 'fdescribe', - 'it', - 'xit', - 'fit', - 'beforeEach', - 'afterEach', - 'beforeAll', - 'afterAll' - ]; - - for (const name of names) { - it(`warns if Env#${name} is monkey patched`, function() { - spyOn(console, 'error'); - const patch = {}; - env[name] = patch; - - // eslint-disable-next-line no-console - expect(console.error).toHaveBeenCalledOnceWith( - jasmine.stringContaining('DEPRECATION: Monkey patching detected.') - ); - // eslint-disable-next-line no-console - expect(console.error).toHaveBeenCalledOnceWith( - jasmine.stringContaining('EnvSpec.js') - ); - expect(env[name]).toBe(patch); - }); - } - }); }); diff --git a/spec/core/jasmineNamespaceSpec.js b/spec/core/jasmineNamespaceSpec.js index 694a1f23..eb69c6be 100644 --- a/spec/core/jasmineNamespaceSpec.js +++ b/spec/core/jasmineNamespaceSpec.js @@ -13,72 +13,7 @@ describe('The jasmine namespace', function() { expect(setDifference(actualKeys, expectedKeys())).toEqual(new Set()); }); - describe('Warning about monkey patching', function() { - beforeEach(function() { - spyOn(console, 'error'); - }); - - for (const key of expectedKeys(false)) { - if (!key.startsWith('MAX_') && key !== 'private' && key !== 'getEnv') { - describe(`jasmine.${key}`, function() { - let orig; - - beforeEach(function() { - orig = jasmineUnderTest[key]; - }); - - afterEach(function() { - jasmineUnderTest[key] = orig; - }); - - it('warns if monkey patched', function() { - const patch = {}; - jasmineUnderTest[key] = patch; - - verifyDeprecation(); - expect(jasmineUnderTest[key]).toBe(patch); - }); - }); - } - } - - // These specs rely on jasmineRequire being exposed. That only happens - // in browsers. - if (typeof document !== 'undefined') { - const statics = ['addMatchers', 'clock', 'createSpyObj']; - - for (const name of statics) { - describe(`jasmine.${name}`, function() { - let bootedCore, env, orig; - - beforeEach(function() { - bootedCore = jasmineRequire.core(jasmineRequire); - env = bootedCore.getEnv(); - jasmineRequire.interface(bootedCore, env); - orig = bootedCore[name]; - }); - - afterEach(function() { - bootedCore[name] = orig; - env.cleanup_(); - }); - - it(`warns if jasmine.${name} is monkey patched`, function() { - const patch = {}; - bootedCore[name] = patch; - - verifyDeprecation(); - expect(bootedCore[name]).toBe(patch); - }); - }); - } - } - }); - - function expectedKeys(includeHtml) { - if (includeHtml === undefined) { - includeHtml = typeof window !== 'undefined'; - } + function expectedKeys() { // Does not include properties added by requireInterface(), since that isn't // called by defineJasmineUnderTest.js/nodeDefineJasmineUnderTest.js. const result = new Set([ @@ -116,7 +51,7 @@ describe('The jasmine namespace', function() { 'getGlobal' ]); - if (includeHtml) { + if (typeof window !== 'undefined') { // jasmine-html.js result.add('HtmlReporterV2'); result.add('HtmlReporterV2Urls'); @@ -139,15 +74,4 @@ describe('The jasmine namespace', function() { return result; } - - function verifyDeprecation() { - // eslint-disable-next-line no-console - expect(console.error).toHaveBeenCalledOnceWith( - jasmine.stringContaining('DEPRECATION: Monkey patching detected.') - ); - // eslint-disable-next-line no-console - expect(console.error).toHaveBeenCalledOnceWith( - jasmine.stringContaining('jasmineNamespaceSpec.js') - ); - } }); diff --git a/src/core/Clock.js b/src/core/Clock.js index 902e1e64..da743cfc 100644 --- a/src/core/Clock.js +++ b/src/core/Clock.js @@ -192,8 +192,6 @@ callbacks to execute _before_ running the next one. setInterval[IsMockClockTimingFn] = true; clearInterval[IsMockClockTimingFn] = true; - j$.private.deprecateMonkeyPatching(this); - return this; // Advances the Clock's time until the mode changes. diff --git a/src/core/Env.js b/src/core/Env.js index 7413776a..eb8cfaae 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -835,8 +835,6 @@ getJasmineRequireObj().Env = function(j$) { this.cleanup_ = function() { uninstallGlobalErrors(); }; - - j$.private.deprecateMonkeyPatching(this, ['deprecated']); } function indirectCallerFilename(depth) { diff --git a/src/core/deprecateMonkeyPatching.js b/src/core/deprecateMonkeyPatching.js deleted file mode 100644 index ca73e764..00000000 --- a/src/core/deprecateMonkeyPatching.js +++ /dev/null @@ -1,22 +0,0 @@ -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; - } - }); - } - } - }; -}; diff --git a/src/core/requireCore.js b/src/core/requireCore.js index e8b70c20..59620525 100644 --- a/src/core/requireCore.js +++ b/src/core/requireCore.js @@ -27,7 +27,6 @@ var getJasmineRequireObj = (function() { }); jRequire.base(j$, globalThis); - j$.private.deprecateMonkeyPatching = jRequire.deprecateMonkeyPatching(j$); j$.private.util = jRequire.util(j$); j$.private.errors = jRequire.errors(); j$.private.formatErrorMsg = jRequire.formatErrorMsg(j$); @@ -103,20 +102,6 @@ var getJasmineRequireObj = (function() { j$.private.loadedAsBrowserEsm = globalThis.document && !globalThis.document.currentScript; - j$.private.deprecateMonkeyPatching(j$, [ - // These are meant to be set by users. - 'DEFAULT_TIMEOUT_INTERVAL', - 'MAX_PRETTY_PRINT_ARRAY_LENGTH', - 'MAX_PRETTY_PRINT_CHARS', - 'MAX_PRETTY_PRINT_DEPTH', - - // These are part of the deprecation warning mechanism. To avoid infinite - // recursion, they're separately protected in a way that doesn't emit - // deprecation warnings. - 'private', - 'getEnv' - ]); - return j$; }; diff --git a/src/core/requireInterface.js b/src/core/requireInterface.js index 0e6e931a..a8833bb1 100644 --- a/src/core/requireInterface.js +++ b/src/core/requireInterface.js @@ -369,7 +369,6 @@ getJasmineRequireObj().interface = function(jasmine, env) { */ jasmine: jasmine }; - const existingKeys = Object.keys(jasmine); /** * Add a custom equality tester for the current scope of specs. @@ -536,7 +535,5 @@ getJasmineRequireObj().interface = function(jasmine, env) { * @namespace asymmetricEqualityTesters */ - jasmine.private.deprecateMonkeyPatching(jasmine, existingKeys); - return jasmineInterface; };