Skip to content
Search

Mocha

lastmod 2022-08-16created 2017-02-1111 edits

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.

Troubleshooting

Close Http Server

When testing with Node, if the server does not shut down, you can fix it as follows. in test:

  before(async () => {
    process.env.PORT = await portfinder.getPortPromise({port: 10002});
    app = require('./../../../app');
  });

  after(async () => {
    require('./../../../app').stop();
  });

and in app:

...

let port = process.env.PORT || 8080;
let server = app.listen(port, () => {
  console.log('App listening on port %s, in environment %s!', port, _.toUpper(process.env.NODE_ENV || ''));
});

function stop() {
  server.close();
}

module.exports = server;
module.exports.stop = stop;

See also

Favorite site

Article

author Zer0 sitemap