Lab&getConfig集成

我正在尝试使用getConfig实验室,但我总是得到一个错误。

在实验室中,我需要服务器,但在searchconfiguration文件时,它会查找node_modules / lab / bin / test_config.json,而不是在根文件夹中查找test_config。

有没有办法使用getConfig将configuration文件传递给实验室?

这是我正在做的一个片段:

//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 }); (...) 

这是错误抛出:

 /index.js:12 host: Cannot read property 'listen' of undefined 

您可以使用GETCONFIG_ROOT环境variables。 从文档 :

在某些情况下,当你的应用程序没有直接运行(例如testing运行器),getconfig可能无法正确查找你的configuration文件。 在这种情况下,您可以将GETCONFIG_ROOT环境variables设置为您的configuration所在的目录。

所以运行你的testing:

 GETCONFIG_ROOT="/path/to/root" make test