5

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?

Denis Tsoi
  • 9,428
  • 8
  • 37
  • 56
Pridkett
  • 4,883
  • 4
  • 30
  • 47

1 Answers1

9

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.

Artem Govorov
  • 903
  • 6
  • 10
  • Excellent. Having Wallaby set my `NODE_ENV` variable to `test` so my app listens on a random port and removing everything in the `workers` property made it work well. – Pridkett May 12 '15 at 14:53