콘텐츠로 이동
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

Node를 테스트로 사용할 경우 서버가 종료되지 않는 현상이 발생될 경우 아래와 같이 해결할 수 있다. 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