首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对Heroku的纱线测试无法连接到我的后端代码。

对Heroku的纱线测试无法连接到我的后端代码。
EN

Stack Overflow用户
提问于 2018-04-25 15:55:55
回答 1查看 82关注 0票数 1

我试图使用下面的app.json通过Heroku管道执行测试

代码语言:javascript
复制
{
  "environments": {
    "test": {
      "addons": [
        {
          "plan": "mongolab:sandbox"
        }
      ],
      "scripts": {
        "test": "yarn test && ((nohup yarn test:start:api &) && sleep 10 && yarn test:integration)"
      }
    }
  }
}

在本地的Linux机器上,命令可以工作,但在Heroku上,我无法访问API服务:

代码语言:javascript
复制
-----> Running test command `yarn test && ((nohup yarn test:start:api &) && sleep 10 && yarn test:integration)`...
yarn run v1.6.0
warning package.json: No license field
$ mocha-webpack --webpack-config ./webpack.config.js --require test/setup.js model/**/*.spec.js api/**/*.spec.js
 WEBPACK  Compiling...
 WEBPACK  Compiled successfully in 792ms
 MOCHA  Testing...
  0 passing (1ms)
 MOCHA  Tests completed successfully
Done in 4.12s.
yarn run v1.6.0
warning package.json: No license field
$ babel-node ./server.js --presets es2015,stage-2
yarn run v1.6.0
warning package.json: No license field
$ mocha-webpack --webpack-config ./webpack.config.js --require test/setup.js model/**/*.integration.js api/**/*.integration.js
 WEBPACK  Compiling...
 WEBPACK  Compiled successfully in 1092ms
 MOCHA  Testing...
  User
Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
(node:570) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
Successfully initialized mongoose-seed
Users collection cleared
Successfully created document [0] of User model
Error: Error: connect ECONNREFUSED 127.0.0.1:8080
...

如何确定连接到API本身(nohup yarn test:start:api &)的URI?

API是用express-restify-mongoose构建的,而且似乎没有像注入hapijs (https://hapijs.com/api#-await-serverinjectoptions)那样的开箱即用的测试。

如何让我的测试在Heroku上运行?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-25 16:44:25

您的测试试图连接到127.0.0.1:8080,但是您的web应用程序几乎可以肯定地运行在其他地方。Heroku environment variable告诉您的后端代码应该使用哪个端口。

尝试更新您的测试,以连接到该变量持有的任何东西,而不是8080。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50026584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档