The issue involves a clear Jest test failure due to an unclosed MessageChannel handle.
The issue describes a Jest test that fails to exit because the Scheduler's MessageChannel handle remains open. The proposed solution involves modifying the Scheduler code to unref the MessageChannel port, which should allow Jest to exit properly. The requirements are clear, and the fix appears to be straightforward.
React version: any Scheduler version: any up to current (0.23.0)
setImmediate function.MessageChannel https://github.com/jsdom/jsdom/issues/2448. If MessageChannel is required to test some important functionality, one can add an implementation from Node.js as recommended in comment https://github.com/jsdom/jsdom/issues/2448#issuecomment-536242756
window.MessageChannel = require('node:worker_threads').MessageChannel;
Link to code example: https://github.com/victor-homyakov/scheduler-jest-jsdom-example
Test is endless. Jest won't stop. Console shows a message
Jest did not exit one second after the test run has completed.
'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
Running Jest with --detectOpenHandles outputs:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● MESSAGEPORT
> 1 | require('scheduler');
| ^
at node_modules/scheduler/cjs/scheduler.development.js:569:17
Code at https://github.com/facebook/react/blob/5426af3d50ff706f3ebeb4764f838e0a3812bf9a/packages/scheduler/src/forks/Scheduler.js#L621 should unref the handle:
channel.port1.onmessage = performWorkUntilDeadline;
// Allow the thread to exit if this is the only active handle in the event system
if (channel.port1.unref) {
channel.port1.unref();
}
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!