Fix setTimeout(() => {}, 0) and align setImmediate behavior with Node.js (#6674)

* Fix setTimeout(() => {}, 0)

* Align `setImmediate` with Node.js

* Update event_loop.zig

* Update test

* use Bun.sleep

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-10-25 02:59:29 -07:00
committed by GitHub
parent c700a70872
commit 7bcf60324a
9 changed files with 169 additions and 30 deletions

View File

@@ -976,8 +976,10 @@ pub const TestCommand = struct {
vm.eventLoop().tick();
var prev_unhandled_count = vm.unhandled_error_counter;
while (vm.active_tasks > 0) {
if (!jest.Jest.runner.?.has_pending_tests) jest.Jest.runner.?.drain();
while (vm.active_tasks > 0) : (vm.eventLoop().flushImmediateQueue()) {
if (!jest.Jest.runner.?.has_pending_tests) {
jest.Jest.runner.?.drain();
}
vm.eventLoop().tick();
while (jest.Jest.runner.?.has_pending_tests) {
@@ -991,6 +993,9 @@ pub const TestCommand = struct {
prev_unhandled_count = vm.unhandled_error_counter;
}
}
vm.eventLoop().flushImmediateQueue();
switch (vm.aggressive_garbage_collection) {
.none => {},
.mild => {