I'm trying to include a module I made, luaScripts.js, into a mocha unit test. Here's what the include looks like in the unit test:
test.js
luaScripts = require("../app/luaScripts.js");
Within luaScripts.js I include a reference to a config file:
luaScripts.js
var fs = require("fs"),
nconf = require("nconf");
nconf.file({ file: "../../config.json" });
var config = nconf.get("dev");
When I try to run the unit test it fails; the reason being that the var config is 'undefined' because the included luaScripts.js cannot read from config.json, It seems like mocha is running the test a directory level lower than expected. If I change the path in luaScripts.js to the following:
nconf.file({ file: "../config.json" });
then the test works fine. However this will break the path for any other modules that use luaScripts.js.
Can anyone explain this bizarre behavior? It seems like the relative paths are messed up when I run my unit tests.
Thanks
Aucun commentaire:
Enregistrer un commentaire