dimanche 13 novembre 2016

Mocha test file runs fine by itself, but fails when run with others

I am trying to test a loopback application. I have a test/index.js file that requires all the tests into the file to run them, as it needs to start the app before, and stop it after:

describe("INTEGRATION TESTING", function() {

  before(function(done) {
    clearDB(app, function() {
      // start the test server and we are done with this before hook
      debug("Starting server...");
      server = app.start(function() {
        debug("READY TO TEST!");
        done();
      });
    });
  });

  after(function(done) {
    server.close(done);
  });

  // load and run all the tests
  [
    "device",
    "event",
    "light",
    "valve"
  ].forEach((model) => {
    require(`./integration/${model}_test`);
  });

});

Each file that is required starts with a describe and most tests run fine. However some tests (for example in "event") will fail. If I use describe.only in event, then all the tests in event will pass. Most of them are asynchronous, using supertest to test the API.

How is this possible and how do you stop tests from interacting.

Aucun commentaire:

Enregistrer un commentaire