1

我想测试我的服务器实际上可以在构建步骤中启动,因此一步运行sails lift(我使用的是sails.js 应用程序)。然后,sails 服务器正常启动,但 5 分钟后超时,导致构建失败。

无论如何我仍然可以让构建通过。也许在 30 秒后,这意味着服务器启动正常,退出我自己并返回 true?

4

1 回答 1

0

我认为你不能那样做。如果您只是想在部署之前检查您的服务器是否会提升,我建议您编写一个测试。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 文档测试部分的建议,您将能够组织您的测试并编写一个。

您将使用mocha运行测试

npm test您可以通过编辑 package.json 来使用命令 的快捷方式:

// 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  
于 2015-10-20T17:26:01.813 回答