我想测试我的服务器实际上可以在构建步骤中启动,因此一步运行sails lift
(我正在使用sails.js应用程序)。 sails服务器然后启动正常,但它在5分钟后超时导致构建失败。
无论如何我仍然可以通过构建。也许在30秒后,这意味着服务器启动正常,退出自己并返回true?
答案 0 :(得分:0)
我认为你做不到。如果您只是想在部署之前检查服务器是否会提升,我建议您编写一个测试。 Sails集成了boostrap.test.js
文件,该文件遵循以下步骤:
1.你的风帆升降机
2.你的测试用完了
3.你的风帆应用降低了
这是执行此操作的文件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