I'm working on a compound js app. In environments/test.js I have exported a variable as follows:
app.host = "http://mysite.com"
When I run the app as below:
NODE_ENV=test node .
I could access the value of host by giving app.host. Everything is fine till here.
I'm using mocha for testing. When I try to access app.host from my test file, I'm getting an error saying,
ReferenceError: app is not defined.
Any idea on how to access the variables from environment/test.js file from test/*.js files would be helpful. Thanks in advance.
environments/test.js
module.exports = {
host: "http://example.com"
};
app.js
var app;
if (process.env.NODE_ENV === "test") {
app = require("./environments/test.js");
}
console.log(app.host);
If you load the module at the top of the Mocha test it should be OK.