Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay restart on watching #2625

Closed
MrZyr0 opened this issue Dec 16, 2020 · 1 comment
Closed

Delay restart on watching #2625

MrZyr0 opened this issue Dec 16, 2020 · 1 comment
Labels

Comments

@MrZyr0
Copy link

MrZyr0 commented Dec 16, 2020

Please provide details about:

  • What you're trying to do : I want to delay reloading ava when using --watch.
  • Why you can't use AVA for this: I didn't see option, parameters are any infomation in the documentation & issue to do this.
  • And maybe how you think AVA could handle this: Add a new parameter in ava.config.js like watchingReloadingDelay that accepts a human readable time like 500ms to add a timeout on the reload action.

Description of the problem

I use nodemon to restart my API every time I modify one of my files (except test files). Sometimes ava reloads at the same time as nodemon and all my tests that make a request to the API fail because of a terminated connection:

Rejected promise returned by test. Reason:

  Error {
    address: '127.0.0.1',
    code: 'ECONNREFUSED',
    errno: -4078,
    port: 4000,
    syscall: 'connect',
    message: 'connect ECONNREFUSED 127.0.0.1:4000',
  }
@novemberborn
Copy link
Member

I use nodemon to restart my API every time I modify one of my files (except test files). Sometimes ava reloads at the same time as nodemon and all my tests that make a request to the API fail because of a terminated connection:

Delaying AVA is not the answer for this. It may still run too early.

Ideally AVA starts the API for you. I do this in test files, even launching child processes. So yes that's a new API process for each test file.

Shared workers could provide a foundation for this as well.

However, for your current setup, the simplest approach might be a before hook:

test.before(async () => {
  let connected = false
  while (!connected) {
    connected = await tryConnection()
  }
})

This stops tests from running until the connection can be established.

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants