mardi 5 mai 2015

require.main.require works but not inside Mocha test

I have written a global function for requiring certain files of my app/framework:

global.coRequireModel = function(name) {
    return require.main.require('./api/_co' + name + '/_co' + name + '.model');
}

This module is in /components/coGlobalFunctions.

It is required in my main app app.js like this:

require('./components/coGlobalFunctions');

Then in other modules using "something" from the framework I use:

var baseScheme = coRequireModel('Base');

This works but not in the Mocha tests which give me a "Error: Cannot find module" right before the require.main.require call.

It seems that the test is coming from another source frolder. But I thought the require.main.require would take out the aspect of having to relatively linking to modules.

EDIT:

An example test file living in api/user:

var should = require('should');
var app = require('../../app');
var User = require('./user.model');
...

Aucun commentaire:

Enregistrer un commentaire