How do you find the stack trace of a JavaScript Promise that never resolves?

65 Views Asked by At

I've written an automated test in Jasmine that tests my asynchronous code. Somewhere in my code, a Promise fails to resolve/reject and Jasmine errors with a timeout:

  Message:
    Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
  Stack:
        at <Jasmine>
        at listOnTimeout (node:internal/timers:573:17)
        at processTimers (node:internal/timers:514:7)

It's not a matter of giving the promise more time. Increasing the timeout has the same effect but with a longer delay.

Unfortunately, that stack trace doesn't lead me to the source of the problem. It's a stack trace to the Jasmine code that interrupted my test, not the part of my code that was waiting to resolve. How do I see the latter?

I'm not sure how much Jasmine factors into a potential solution. For example, Java has ways to see all the threads in a program. Does Node.JS have something similar? Is there a library or node.js setting that makes promises more verbose?

I'm using node v20.10.0.

0

There are 0 best solutions below