1

I'm trying to use Lab with getConfig but i'm always getting an error.

In Lab I require the server, but when searching for the config file it looks into the node_modules/lab/bin/test_config.json instead of looking for the test_config in the root folder.

Is there any way to pass the config file to lab using getConfig?

Here's a snippet of what I'm doing:

//In the testFile.js
var Lab = require("lab");
var server = require("../index");
(...)

//In index.js
(...)
var config = require('getconfig');
(...)
var server = new Hapi.Server();
server.connection({
  host: config.http.listen,
  port: config.http.port
});
(...)

And this is the error throw:

/index.js:12
host: Cannot read property 'listen' of undefined
Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
pmvrmc
  • 33
  • 5

1 Answers1

2

You can use the GETCONFIG_ROOT environment variable. From the documentation:

In certain circumstances, when your app isn't run directly (e.g. test runners) getconfig may not be able to lookup your config file properly. In this case, you can set a GETCONFIG_ROOT environment variable to the directory where your configs are held.

So run your tests like this:

GETCONFIG_ROOT="/path/to/root" make test
Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94