Tag: 实验室

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

如何在运行时使用node-config覆盖configuration值?

我想在testing时重写一些值,特别是将http服务的重试设置为1(立即失败,不重试)。 我们的项目使用node-config 。 根据文档我可以用NODE_CONFIG envvariables覆盖: node myapp.js –NODE_CONFIG='{"Customer":{"dbConfig":{"host":"customerdb.prod"}}}' 那么我宁愿在我的testing中这样做,但不是所有的testing。 代码说你可以通过设置ALLOW_CONFIG_MUTATIONS来允许configurationALLOW_CONFIG_MUTATIONS 。 process.env.ALLOW_CONFIG_MUTATIONS = "true"; const importFresh = require('import-fresh'); importFresh("config"); process.env.NODE_CONFIG = JSON.stringify({httpServices:{integration:{enrich: {retryInterval: 1, retries: 1}}}}); expect(process.env.NODE_CONFIG, 'NODE_CONFIG not set').to.exist(); expect(process.env.NODE_CONFIG, 'NODE_CONFIG not set').to.match(/retryInterval/); expect(process.env.ALLOW_CONFIG_MUTATIONS, 'ALLOW_CONFIG_MUTATIONS not set').to.equal("true"); const testConfig = require("config"); console.dir(testConfig.get("httpServices.integration.enrich")); expect(testConfig.get("httpServices.integration.enrich.retryInterval"), 'config value not set to 1').to.equal(1); 结果: { url: 'https://internal-**********', retryInterval: […]

实验室返回错误没有方法“实验”

我正在写一个函数的testing代码,将检查在Twitter中的用户名的存在。 我正在使用Hapi框架和实验室进行testing。 当我运行npm test出现以下错误: > NameGen@0.0.0 test /Users/mario/projects/NameGen > ./node_modules/lab/bin/lab -c /Users/mario/projects/NameGen/test/test.js:5 Lab.experiment( "Test Username Existence", function() { ^ TypeError: Object #<Object> has no method 'experiment' at Object.<anonymous> (/Users/mario/projects/NameGen/test/test.js:5:5) at Module._compile (module.js:456:26) at Object.Module._extensions..js [as origLoader] (module.js:474:10) at Object.require.extensions..js (/Users/mario/projects/NameGen/node_modules/lab/lib/coverage.js:32:26) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at /Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:85:23 at […]

如何使用Hapi.js实验室testing框架在控制台上进行debugging?

Mocha可以select使用mocha debug来运行testing,就像node debug ,允许在REPL控制台内进行debugging。 我如何使用Hapi Lab进行REPLdebugging?

`lab`和`code`与`mocha`和`chai` nodejs库之间的比较

我是node.js的新手,我决定使用hapijs来实现我的web和API。 但是,我发现hapi社区为testing和断言库build立和使用lab和code ,这是对mocha和chai的重写。 我很难find这些库之间的差异。 我知道有可能互换使用它们,但是我想要更详细的比较,因为我想定义和遵守编码标准,而且我不喜欢图书馆的混合和匹配,除非有正当的理由。 任何反馈意见

在单独的文件中testingMongoose模型会导致问题(使用Mockgoose&Lab)

每当一个Mongoose模型在加载之后试图加载,就会抛出一个错误,例如: 错误:uncaughtException:编译后无法覆盖Account模型。 date = Fri Feb 26 2016 10:13:40 GMT-0700(MST),pid = 19231,uid = 502,gid = 20,cwd = / Users / me / PhpstormProjects / project,execPath = / usr / local / Cellar / node / 0.12.4 / bin / node,version = v5.2.0,argv = [/ usr / local / Cellar / node / 0.12.4 / bin […]