npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jest-fixup-timeouts

v0.0.0

Published

Improve the timeout errors provided by Jest.

Readme

jest-fixup-timeouts

Improve the timeout errors provided by Jest.

When a timeout occurs, you get an exception and a stack trace. This is an improvement over Jest's previous behaviour, where you only get to see the test name.

Screenshots

Here, we've timed out during a sleep inside application code. You get a stack back to the test that called the application code:

 FAIL  test/sleepy.spec.ts
  ✕ testy mctestface (184 ms)

    deadline exceeded (waited here for 123ms)

      3 | export async function mySleep(duration: number) {
    > 4 |   return await sleep(duration);
        |   ^
      5 | }

      at Object.mySleep (src/index.ts:4:3)
      at Object.<anonymous> (test/sleepy.spec.ts:6:3)

If you don't want to mess with your application code, you could also see where the test was when it timed out:

 FAIL  test/sleepy.spec.ts
  ✕ testy mctestface (184 ms)

    deadline exceeded (waited here for 125ms)

      4 | test('stuff', async () => {
      5 |   await sleep(55);
    > 6 |   await mySleep(500);
        |   ^
      7 | }, 200);

      at Object.<anonymous> (test/sleepy.spec.ts:6:3)

For comparison, here is the original Jest error:

    thrown: "Exceeded timeout of 200 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
    > 4 | test('stuff', async () => {
        | ^

      at Object.<anonymous> (test/sleepy.spec.ts:4:1)

How does it work?

We compute a deadline, then check it in various places. When it is exceeded, throw a regular exception and let the test framework deal with that failure.

Computing the deadline

A custom environment, jest-fixup-timeouts/environment, hooks into jest-circus' test events to observe the start of a test. At this point, you can compute the deadline (the wall-clock time at which the test must have finished), and store it.

I have chosen to store it as test.deadline, which is available everywhere.

As a helper, it also provides expect.withinDeadline(promise), which races the promise against the deadline.

Note, because I can't work out how to phrase this in a way that is clear: test and expect here refer to the Jest globals, which are normally injected.

Checking the deadline

A babel plugin, jest-fixup-timeouts/rewrite-awaits, transforms await foo() into await expect.withinDeadline(foo()).

You can apply this plugin wherever you want. For example, you might want to only apply it to tests, or to certainly bits of your infrastructure code (e.g. your RPC library?), or you can write out the expect.withinDeadline by hand.

e.g.

{
  plugins: ['jest-fixup-timeouts/rewrite-awaits']
}
{
  overrides: [{
    test: ['**/*.spec.ts', '**/rpc/*'],
    plugins: ['jest-fixup-timeouts/rewrite-awaits']
  }]
}

Status

This is a straw-man (hack) implementation which depends on some implementation details, but isn't actually significantly worse than the patch would be for Jest.

Currently, it only checks for timeouts during await, but this is a good approximation, it appears.