DEV Community

Marc Ziel
Marc Ziel

Posted on

6

increasing test timeout in jest while debugging

When debugging code, the script execution takes substantially more time which sometimes leads to very strange errors when an asyc test is failed due to exceeding the time specified in jest.setTimeout which causes the next test to execute while the previous test is still running in the background.

Fortunately, we can change the default time using --setupTestFrameworkScriptFile option that should point to a file in which we change the timeout:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10 * 60 * 1000;

We can put this file in the home directory and run jest with changed timeouts from anywhere with a little bit of command line magic:

node --inspect-brk node_modules/.bin/jest --runInBand --setupTestFrameworkScriptFile="${HOME}/test-setup.js"

Another cool thing is that if we also have a setup file in our project, both files are used (but values from file given through command line option take precedence).

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay