jeudi 23 mai 2019

Can't stop express server in after function

I have Node tests with this before function:

before((done) => {
  app.startServer()
    .catch((err) => {
      done(err);
  });
});

I'm now trying to write an after function which will stop the server.

I had hoped this could be:

after(() => {
  app.stopServer(apiAddress)
    .catch((err) => {
      done(err);
    })
});

but that doesn't work.

These are my express.js functions:

function startServer() {
  return new Promise((resolve, reject) => {
    app.listen(PORT, (err) => {
      if (err) reject(err);
      log.info(`Server listening on port ${PORT}`);
      resolve();
    });
  });
}

function stopServer(url) {
  return new Promise((resolve, reject) => {
    //const server = app.listen(url);
    app.close(url, (err) => {
      if (err) reject(err);
      log.info(`Server closed on ${url}`);
      resolve();
    });
  });
}

How do I stop my express server in an after function?

Aucun commentaire:

Enregistrer un commentaire