vendredi 2 septembre 2016

Mocha / Chair - run test in multiple files

I have a common test I want to run in multiple test files, I did some research and this is the suggested solution I found to include tests in a file:

Directory Structure:

|--test
   |--common
      |--common.js
   |--common_functions.js
   |--helpers.js
   |--registration.js

common.js

var helpers = require("../../services/helpers");
var chai = require("chai");
var expect = require("chai").expect;
chai.should();
chai.use(require("chai-things"));
var testData = require("../../config/testData");

  it('check if we are connected to local test db', function(done) {
      helpers.checkTestDB(function(err, result) {
          expect(err).to.equal(null);
          result.should.equal('This is the test DB');
          done();
      });
  });

common_functions.js

exports.importTest = function(name, path) {
    describe(name, function () {
        require(path);
    });
}

helpers.js / registration.js

...
var common_functions = require('./common_functions');
...
describe("Common Tests Import", function(){
  common_functions.importTest("checkDb",'./common/common');
});

The problem is that the test only runs on one of the two files, if I leave it in both it runs on helpers, if I comment out helpers, the registration one runs, is there a way to run it in each of these?

The reason being is that I'm setting the env variable in each file to use a test db, but there is a lot going on and in case it somehow changes I'd like it to run on each file separately.

Aucun commentaire:

Enregistrer un commentaire