From e9e61569e71d49bc5271389e3cfafdc0caa922c7 Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Sun, 10 Aug 2025 16:22:47 +0200 Subject: [PATCH] refactor(zone.js): remove unused jasmine globalerror monkey patching. This is for testing purposes for now. See discussion on the related issue. fixes #63072 --- packages/zone.js/lib/jasmine/jasmine.ts | 43 ------------------- .../test/node_bluebird_entry_point.init.ts | 23 ---------- 2 files changed, 66 deletions(-) diff --git a/packages/zone.js/lib/jasmine/jasmine.ts b/packages/zone.js/lib/jasmine/jasmine.ts index f0897da8ba11..43b56d50adaa 100644 --- a/packages/zone.js/lib/jasmine/jasmine.ts +++ b/packages/zone.js/lib/jasmine/jasmine.ts @@ -55,49 +55,6 @@ export function patchJasmine(Zone: ZoneType): void { (global[symbol('fakeAsyncPatchLock')] === true || global[symbol('fakeAsyncAutoFakeAsyncWhenClockPatched')] === true); - const ignoreUnhandledRejection = global[symbol('ignoreUnhandledRejection')] === true; - - if (!ignoreUnhandledRejection) { - const globalErrors = (jasmine as any).GlobalErrors; - if (globalErrors && !(jasmine as any)[symbol('GlobalErrors')]) { - (jasmine as any)[symbol('GlobalErrors')] = globalErrors; - (jasmine as any).GlobalErrors = function () { - const instance = new globalErrors(); - const originalInstall = instance.install; - if (originalInstall && !instance[symbol('install')]) { - instance[symbol('install')] = originalInstall; - instance.install = function () { - const isNode = typeof process !== 'undefined' && !!process.on; - // Note: Jasmine checks internally if `process` and `process.on` is defined. - // Otherwise, it installs the browser rejection handler through the - // `global.addEventListener`. This code may be run in the browser environment where - // `process` is not defined, and this will lead to a runtime exception since webpack 5 - // removed automatic Node.js polyfills. Note, that events are named differently, it's - // `unhandledRejection` in Node.js and `unhandledrejection` in the browser. - const originalHandlers: any[] = isNode - ? process.listeners('unhandledRejection') - : global.eventListeners('unhandledrejection'); - const result = originalInstall.apply(this, arguments); - isNode - ? process.removeAllListeners('unhandledRejection') - : global.removeAllListeners('unhandledrejection'); - if (originalHandlers) { - originalHandlers.forEach((handler) => { - if (isNode) { - process.on('unhandledRejection', handler); - } else { - global.addEventListener('unhandledrejection', handler); - } - }); - } - return result; - }; - } - return instance; - }; - } - } - // Monkey patch all of the jasmine DSL so that each function runs in appropriate zone. const jasmineEnv: any = jasmine.getEnv(); ['describe', 'xdescribe', 'fdescribe'].forEach((methodName) => { diff --git a/packages/zone.js/test/node_bluebird_entry_point.init.ts b/packages/zone.js/test/node_bluebird_entry_point.init.ts index c374d8bd7bad..947c3be51e4a 100644 --- a/packages/zone.js/test/node_bluebird_entry_point.init.ts +++ b/packages/zone.js/test/node_bluebird_entry_point.init.ts @@ -43,26 +43,3 @@ patchTaskTracking(Zone); patchWtf(Zone); patchRxJs(Zone); patchPromiseTesting(Zone); - -const globalErrors = (jasmine as any).GlobalErrors; -const symbol = Zone.__symbol__; -if (globalErrors && !(jasmine as any)[symbol('GlobalErrors')]) { - (jasmine as any)[symbol('GlobalErrors')] = globalErrors; - (jasmine as any).GlobalErrors = function () { - const instance = new globalErrors(); - const originalInstall = instance.install; - if (originalInstall && !instance[symbol('install')]) { - instance[symbol('install')] = originalInstall; - instance.install = function () { - const originalHandlers = process.listeners('unhandledRejection'); - const r = originalInstall.apply(this, arguments); - process.removeAllListeners('unhandledRejection'); - if (originalHandlers) { - originalHandlers.forEach((h) => process.on('unhandledRejection', h)); - } - return r; - }; - } - return instance; - }; -}