Skip to content

Commit 72c658b

Browse files
committed
core: Refactor Node.js Unhandled Rejection Handling to process.emit Interception (#8896)
1 parent f634f0c commit 72c658b

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/Neo.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,15 +1190,19 @@ if (typeof globalThis.addEventListener === 'function') {
11901190
e.preventDefault()
11911191
}
11921192
})
1193-
} else if (typeof process !== 'undefined' && typeof process.on === 'function') {
1193+
} else if (typeof process !== 'undefined' && typeof process.emit === 'function') {
11941194
// Node.js
1195-
process.on('unhandledRejection', e => {
1196-
if (e === Neo.isDestroyed) {
1197-
return
1195+
// We need to intercept the emit, since test runners like Playwright
1196+
// will listen to unhandledRejection and fail the test
1197+
const originalEmit = process.emit;
1198+
1199+
process.emit = function(name, data, ...args) {
1200+
if (name === 'unhandledRejection' && data === Neo.isDestroyed) {
1201+
return true
11981202
}
11991203

1200-
throw e
1201-
})
1204+
return originalEmit.apply(this, arguments)
1205+
}
12021206
}
12031207

12041208
export default Neo;

test/playwright/setup.mjs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,4 @@ export function setup(options = {}) {
5151
Neo.apps ??= {};
5252
Neo.apps[appConfig.windowId || 1] = finalAppConfig;
5353
Neo.appsByName = {[finalAppConfig.name]: [finalAppConfig]};
54-
55-
// Global safeguard: Intercept and suppress Neo.isDestroyed unhandled rejections.
56-
// This allows floating promises (like timeouts) to reject safely during test teardown.
57-
const originalEmit = process.emit;
58-
process.emit = function (name, data, ...args) {
59-
if (name === 'unhandledRejection' && data === Symbol.for('Neo.isDestroyed')) {
60-
return true;
61-
}
62-
return originalEmit.apply(this, arguments);
63-
};
6454
}

0 commit comments

Comments
 (0)