A small utility module to check if a service is up and running at a given url.
Often when testing your code against dependent (micro)services, it's required to defer the test run until a given dependency is up and running - usually meaning it responds with a 2XX HTTP status-code at a dedicated health-check endpoint. Since services tend to have a relatively long starup time (imagine a JVM-based, dockerized service started as a test-dependency), it's often required to attempt the readiness call at given intervals for a certain period of time to allow the service to start-up and respond.
Using Readiness in tests
Whether you're using Jest or Mocha, using readiness looks quite the same. I'll use Jest to demonstrate:
const readiness =;
The call to
readiness makes sure the the other service we depend on is ready (in the default use-case, responds with a 2XX status-code), and only then resolves the promise that signals
beforeAll() to complete.
readiness supports additional options that control the check procedure, and can be passed as a second argument to the
options.attempts- the number of attempts to call the service before it's declared unavailble, rejecting the promise. Defaults to 1.
options.interval- the interval (in milliseconds) between consequent attempts to invoke the service. Effective only when
options.attemptsis greater than 1, and defaults to 200ms.
options.customCheck- a custom function that allows overriding the default readiness-check logic. Accepts the
node-fetchresponse as an input, and expected to resolve if the response is considered to be from a healthy service, or reject otherwise. An example use-case is when you consider a service ready if it returns a 401 response code, since you cannot or does not want to authenticate against the health-check endpoint.
const readiness =;