• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KablamoOSS / kerosene / 10839628454

12 Sep 2024 10:23PM CUT coverage: 79.926%. Remained the same
10839628454

push

github

web-flow
build(deps): bump path-to-regexp from 6.2.1 to 6.3.0 (#148)

224 of 282 branches covered (79.43%)

868 of 1086 relevant lines covered (79.93%)

6.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/kerosene/src/function/waitForEventLoopToDrain.ts
1
import globalThis from "core-js-pure/features/global-this";
×
2

3
// Grab a reference to the global `setImmediate` and `setTimeout` so mocking libraries like `sinon` don't interfere
4
const { setImmediate, setTimeout } = globalThis;
×
5

6
/**
7
 * Returns a Promise that resolves when the event loop has drained
8
 *
9
 * This can be useful in unit testing where you need to wait for `Promise` to resolve but you do
10
 * not have access to it (i.e. it isn't returned, such as in `useEffect()` in React)
11
 *
12
 * NOTE: This function uses its own reference to the global `setImmediate` so mocking libraries
13
 * like `sinon` do not replace the internal `setImmediate` used to wait for the event loop to drain
14
 */
15
export default function waitForEventLoopToDrain(): Promise<void> {
×
16
  return new Promise<void>((resolve) => {
×
17
    if (setImmediate) {
×
18
      setImmediate(resolve);
×
19
    } else if (
×
20
      typeof jest !== "undefined" &&
×
21
      typeof jest.requireActual === "function"
22
    ) {
23
      // jest-environment-jsdom removes `setImmediate` from the Node globals, so instead use jest to require the Node
24
      // API from the "timers" module. We can't just do `import { setImmediate } from "timers";` because of the browser
25
      jest
×
26
        .requireActual<typeof import("timers")>("timers")
27
        .setImmediate(resolve);
28
    } else {
29
      // Fallback to setTimeout
30
      setTimeout(resolve, 0);
×
31
    }
32
  });
33
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc