Hook timeout on vow

Running a test that does some slow actions on the after() hook, it keeps timing out intermittently.

Is there a way to disable the hook timeout? Cheers.

1 Like

Here’s one option for it Error: Test timeout

If you set timeout to 0 it will be disabled https://github.com/thetutlage/japa#test-timeouts

That doesn’t seem to work with the after hook. The code is using some await as:

after(async () => {
  await transData.from.user.delete()
  for (let target of transData.to ) {
    await target.shop.delete()
    await target.order.delete()

I get TypeError: Cannot read property 'timeout' of undefined.

Aah didn’t notice that.
I know I had same problem for one project where I no longer have access to, but I can’t really remember if or how it was solved. I’ll test around maybe I can find something :slight_smile:

Meanwhile there should be way to make this delete slightly faster running multiple of those at once with something like this:

after(async () => {
  await transData.from.user.delete()
  let promises = []
  for (let target of transData.to ) {
  await Promise.all(promises)

(someone here in forums had cleaner solution with .map() too that I keep forgetting)

1 Like

The dirty way I though of is to replace the after() hook with a test, but then it does’t play well with the DatabaseTransactions hook. Speeding up the execution is hit and miss.

Feels like a missing feature?

So, this is becoming kind of a big deal. If the before hook times out then the data populated is inconsistent and makes the other tests fail at random points.

Unless someone is aware of a non-documented solution then I am thinking a GitHub Issue is in order to:

  1. Introduce the timeout function on the hooks.
  2. Ideally, make the DatabaseTransactions optional per test.

Any thoughts before I create the issue?

perhaps this?

after(async () => {
  await transData.from.user.delete()

  await Promise.all(
     ({ shop, order}) =>  [shop.delete(), order.delete()]

To solve this, you can store the original hook value and restore it after use.

You can do something like:

const originalHashHook = Hash.make();

// temp method override
const Hask.make = async () => {
   // something

// fake hash hook use
await Hash.make(user.password)

// restore the original value
Hash.make = originalHashHook;

Does the introduction of the timeout function on the hooks make the test duration much longer?

(Disregard possible syntax errors because I’m not writing in my code editor)