Set jest testTimeout

hey, folks! I’m trying to set the jest config attribute testTimeout in my rw api.

I tried:

  • ./jest.config.js in the project root
  • ./api/jest.config.js
  • passing it as a flag like yarn rw test -- --testTimeout=10000
  • setting it as the last argument to the scenario function E.g. - scenario('returns all bills', /* test body callback */, 10000)

In most cases it seems to be ignored or maybe overwritten, but in the case of setting it in ./api/jest.config.js I do get a message saying the attribute is unknown.

● Validation Warning:

  Unknown option "testTimeout" with value 10000 was found.
  This is probably a typing mistake. Fixing it will remove this message.

I tried it both as a string and a number in this last case, just in case, but no love.

Any idea how to set the jest timeout?


Putting jest.setTimeout(10000) in the test file itself works.

1 Like

Glad you got the tests working, though I would have thought you could have set that in the projects config per side: Project Configuration | RedwoodJS Docs

Might I ask what tests could take 10s to run locally? Is there a root issue behind having to up the timeout we should be aware of?

Thanks for the attention!

That’s my belief as well, so I opened a bug. (same info, just in bug form) [Bug]: cannot set jest testTimeout · Issue #9712 · redwoodjs/redwood · GitHub

It is odd that the tests run so slowly, but I’m not sure that’s redwood’s problem yet.

When I run with postgres in docker locally, the full suite of mostly generated tests, about 92 of them, completes in about 14 seconds.

When my TEST_DATABASE_URL points to postgres on AWS or on Railway, some tests are taking the ballpark of 8 seconds (hence the timeout at 5s).

The tests are pretty lightweight. I assumed it was some connection pool or similar config error I made.

What makes me think it could be something in rw is that it happens both on Railway and AWS.

Further weirdness, it has run successfully on Github Actions.

I thought it could be my network, but my bandwidth is good (E.g. - streaming video up and down, often multiple streams at once is normal and fine) and these tests are fetching like 2 rows of 8 columns of data or less.

Maybe something in the scenario seeding is blocking, or there’s just enough network latency to introduce a race condition that I don’t see locally?

Thanks again!

Hi @ThomasGHenry and thanks for the GH issue write up – I’ll follow up more there with details and any progress.

That said, testing using a remote database will always be significantly slower due to:

  • network
  • latency
  • the availability/plan for the database in general some free tier databases are slower across board than paid counterparts for understandable reasons)
  • the test strategy of resetting/cleaning ou the data base to a known state per test is expensive … and that work takes more time per above)

So, we always recommend testing with a local database of the same flavor (ie, test PG with PG).

A tool like can help here.

Also, an upcoming PR feat(describeScenario): Seed scenario once and group tests by dac09 · Pull Request #9572 · redwoodjs/redwood · GitHub will add a describeScenario to speed things up by running and setting up a scenario with data and running the same for all tests rather that resetting per each test.

Oh, one other thing I thought of and wanted to ask @ThomasGHenry – did you confirm that the test times out or was it ever the database connection timing out?

@ThomasGHenry are you on the recent version?