Heroku 上的 Yarn 测试无法连接到我的后端代码
Yarn tests on Heroku fail to connect to my back-end code
我正在尝试使用以下 app.json
:
通过 Heroku 管道执行测试
{
"environments": {
"test": {
"addons": [
{
"plan": "mongolab:sandbox"
}
],
"scripts": {
"test": "yarn test && ((nohup yarn test:start:api &) && sleep 10 && yarn test:integration)"
}
}
}
}
在我的 Linux 机器上,该命令在本地有效,但在 Heroku 上我无法访问 API 服务:
-----> 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 上进行测试 运行?
您的测试正在尝试连接到 127.0.0.1:8080
,但您的 Web 应用程序几乎可以肯定是 运行 其他地方。 Heroku provides the PORT
environment variable 告诉您的后端代码它应该使用哪个端口。
尝试更新您的测试以连接到该变量包含的任何内容,而不是 8080。
我正在尝试使用以下 app.json
:
{
"environments": {
"test": {
"addons": [
{
"plan": "mongolab:sandbox"
}
],
"scripts": {
"test": "yarn test && ((nohup yarn test:start:api &) && sleep 10 && yarn test:integration)"
}
}
}
}
在我的 Linux 机器上,该命令在本地有效,但在 Heroku 上我无法访问 API 服务:
-----> 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 上进行测试 运行?
您的测试正在尝试连接到 127.0.0.1:8080
,但您的 Web 应用程序几乎可以肯定是 运行 其他地方。 Heroku provides the PORT
environment variable 告诉您的后端代码它应该使用哪个端口。
尝试更新您的测试以连接到该变量包含的任何内容,而不是 8080。