我想测试我的服务器是否实际上可以在构建步骤中启动,以便一步运行 sails lift
(我正在使用 sails.js 应用程序)。 sails 服务器随后正常启动,但 5 分钟后超时,导致构建失败。
无论如何我仍然可以让构建通过。也许 30 秒后,这意味着服务器启动正常,退出并返回 true?
最佳答案
我认为你不能这样做。如果您只是想在部署之前检查服务器是否会提升,我建议您编写一个测试。 Sails 集成了一个 boostrap.test.js
文件,该文件遵循以下步骤:
1.您的 sails 应用程序提升
2.您的测试已运行
3.你的sails应用程序降低
这是执行此操作的文件 bootstrap.test.js
:
var Sails = require('sails'),
sails;
before(function(done) {
// Increase the Mocha timeout so that Sails has enough time to lift.
this.timeout(5000);
Sails.lift({
// configuration for testing purposes
}, function(err, server) {
sails = server;
if (err) return done(err);
// here you can load fixtures, etc.
done(err, sails);
});
});
after(function(done) {
// here you can clear fixtures, etc.
Sails.lower(done);
});
遵循sails documentation testing section的建议您将能够组织测试并编写测试。
您将使用 mocha 运行测试
您可以通过编辑 package.json 来获得 npm test
命令的快捷方式:
// package.json
scripts": {
"start": "node app.js",
"debug": "node debug app.js",
"test": "mocha test/bootstrap.test.js test/unit/**/*.test.js"
},
关于 Wercker,在使用类似的东西运行测试之前,您必须在其中一个步骤中安装 mocha:
# Docker container based on lastest stable iamge of node on DockerHub
box:node
build:
steps:
# Install your project dependencies (npm)
-npm-install
# Install mocha globally
- script:
name: Install mocha globaly
code: npm install -g mocha
# Run your tests
-npm-test
deploy:
steps:
# deploy your application
关于node.js - 在 wercker.yml 文件的构建步骤中停止运行服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31028978/