Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding EADDRINUSE when using wallaby.js with an express project

I've had great luck using wallaby.js on client side JavaScript and I'd like to try to get it to work on my server side JavaScript. However, wallaby.js likes to spin up a lot of parallel web servers which causes problems for the tests because it keeps on throwing EADDRINUSE errors.

The basic scaffolding of my project was done with the Yeoman angular-fullstack generator, so my server code sits in /server and most of the methods are in /server/api.

Thus far, I've managed to get it to kinda work with the following configuration:

module.exports = function () {
  return {
    files: [
      'server/**/*.js',
      { pattern: 'server/**/*.spec.js', ignore: true }
    ],

    tests: [
      'server/**/*.spec.js'
    ],

    env: {
      type: 'node',

    },

    debug: true,
    workers: {
      initial: 1,
      regular: 1,
      recycle: false
    }
  };
};

Here you can see that I'm setting the number of wallaby workers to 1 and not allowing it to recycle workers. It works fine the first time through, but after I start to edit files I get occasional EADDRINUSE errors.

Is there a preferred mechanism for using wallaby.js with express and avoiding it from spawning multiple test server processes all on the same port, thereby eliminating the EADDRINUSE errors?

like image 792
Pridkett Avatar asked May 11 '15 21:05

Pridkett


1 Answers

The name is a bit confusing, but recycle: true will do trick. recycle: false means that once started node processes will be reused forever.

I understand it's not always possible to use parallel processes (especially with DB tests), but to make it work for a web server, you may specify 0 as a port when running tests, so it'll pick and use a random one.

  var server  = require('http').createServer();
  server.listen(0);

This way wallaby will be able to run your tests in parallel and reuse processes.

like image 56
Artem Govorov Avatar answered Nov 13 '22 09:11

Artem Govorov